Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test\Passed event is not emitted for PHPT tests #5898

Closed
Bilge opened this issue Jul 14, 2024 · 5 comments
Closed

Test\Passed event is not emitted for PHPT tests #5898

Bilge opened this issue Jul 14, 2024 · 5 comments
Assignees
Labels
feature/events Issues related to PHPUnit's event system feature/phpt End-to-end tests in PHPT format feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11

Comments

@Bilge
Copy link
Contributor

Bilge commented Jul 14, 2024

Q A
PHPUnit version 10.5.27
PHP version 8.2.15
Installation Method Composer

Summary

When a test succeeds, it usually emits the PHPUnit\Event\Test\Passed event. When it fails (an assertion), it emits PHPUnit\Event\Test\Failed. However, PHPT tests do not follow suit; they do correctly emit the Failed event, but the Passed event is not so emitted. They do emit AssertionSucceeded, but as this is marked @deprecated, one supposes one cannot rely on this (and it is removed in v11).

Current behavior

PHPT tests do not emit the PHPUnit\Event\Test\Passed event when they pass.

How to reproduce

Write PHPT test with --EXPECTF-- section that passes.

Expected behavior

PHPUnit\Event\Test\Passed event is emitted.

@Bilge Bilge added the type/bug Something is broken label Jul 14, 2024
@sebastianbergmann sebastianbergmann added feature/phpt End-to-end tests in PHPT format feature/test-runner CLI test runner feature/events Issues related to PHPUnit's event system labels Jul 14, 2024
@sebastianbergmann sebastianbergmann changed the title PHPT tests do not emit PHPUnit\Event\Test\Passed event Test\Passed event is not emitted for PHPT tests Jul 14, 2024
@sebastianbergmann sebastianbergmann added version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 labels Jul 14, 2024
@sebastianbergmann
Copy link
Owner

Confirmed for both PHPUnit 10 and PHPUnit 11. Thank you for reporting this!

@sebastianbergmann
Copy link
Owner

This should be as simple as

diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php
index 584de6151..f2c18ec86 100644
--- a/src/Runner/PhptTestCase.php
+++ b/src/Runner/PhptTestCase.php
@@ -199,6 +199,8 @@ public function run(): void
             );
         }
 
+        $passed = true;
+
         try {
             $this->assertPhptExpectation($sections, $this->output);
         } catch (AssertionFailedError $e) {
@@ -232,8 +234,16 @@ public function run(): void
             } else {
                 $emitter->testFailed($this->valueObjectForEvents(), ThrowableBuilder::from($failure), null);
             }
+
+            $passed = false;
         } catch (Throwable $t) {
             $emitter->testErrored($this->valueObjectForEvents(), ThrowableBuilder::from($t));
+
+            $passed = false;
+        }
+
+        if ($passed) {
+            $emitter->testPassed($this->valueObjectForEvents());
         }
 
         $this->runClean($sections, CodeCoverage::instance()->isActive());

@sebastianbergmann sebastianbergmann self-assigned this Jul 14, 2024
@Bilge
Copy link
Contributor Author

Bilge commented Jul 14, 2024

That does seem to work, yes.

@Bilge
Copy link
Contributor Author

Bilge commented Jul 15, 2024

Thank you for the quick fix on this one.

@Bilge
Copy link
Contributor Author

Bilge commented Jul 18, 2024

Looking forward to the tag for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/events Issues related to PHPUnit's event system feature/phpt End-to-end tests in PHPT format feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11
Projects
None yet
Development

No branches or pull requests

2 participants