JUnit XML logger does not handle assertion failures in before-test methods #5561
Labels
feature/logging/junit
Issues related to logging test results in JUnit XML format
feature/logging
Issues related to logging test results
feature/test-runner
CLI test runner
type/bug
Something is broken
version/10
Something affects PHPUnit 10
Summary
On a failed assertion in setUp, phpunit fails with an internal error.
I am unsure, if assertions are allowed in setUp, the documentation only disallows them in setUpBeforeClass.
Issue was previously reported as #5549, but at the time due to an incorrect analysis on my side I was not able to narrow the root cause down. I updated #5549 with the minimal test case as well.
Current behavior
When running the test with the failed assertion, following happens:
An error occurred inside PHPUnit.
Message: PHPUnit\Event\Telemetry\HRTime::duration(): Argument #1 ($start) must be of type PHPUnit\Event\Telemetry\HRTime, null given, called in phar:///usr/local/bin/phpunit/phpunit/Logging/JUnit/JunitXmlLogger.php on line 191
Location: phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:48
#0 phar:///usr/local/bin/phpunit/phpunit/TextUI/Application.php(144): PHPUnit\TextUI\TestRunner->run()
#1 /usr/local/bin/phpunit(2976): PHPUnit\TextUI\Application->run()
#2 {main}
Caused by: phar:///usr/local/bin/phpunit/phpunit/Event/Value/Telemetry/HRTime.php:54
#0 phar:///usr/local/bin/phpunit/phpunit/Logging/JUnit/JunitXmlLogger.php(191): PHPUnit\Event\Telemetry\HRTime->duration()
#1 phar:///usr/local/bin/phpunit/phpunit/Logging/JUnit/JunitXmlLogger.php(148): PHPUnit\Logging\JUnit\JunitXmlLogger->handleFinish()
#2 phar:///usr/local/bin/phpunit/phpunit/Logging/JUnit/Subscriber/TestFinishedSubscriber.php(29): PHPUnit\Logging\JUnit\JunitXmlLogger->testFinished()
#3 phar:///usr/local/bin/phpunit/phpunit/Event/Dispatcher/DirectDispatcher.php(78): PHPUnit\Logging\JUnit\TestFinishedSubscriber->notify()
#4 phar:///usr/local/bin/phpunit/phpunit/Event/Dispatcher/DeferringDispatcher.php(41): PHPUnit\Event\DirectDispatcher->dispatch()
#5 phar:///usr/local/bin/phpunit/phpunit/Event/Emitter/DispatchingEmitter.php(548): PHPUnit\Event\DeferringDispatcher->dispatch()
#6 phar:///usr/local/bin/phpunit/phpunit/Framework/TestRunner.php(152): PHPUnit\Event\DispatchingEmitter->testFinished()
#7 phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php(436): PHPUnit\Framework\TestRunner->run()
#8 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(266): PHPUnit\Framework\TestCase->run()
#9 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(266): PHPUnit\Framework\TestSuite->run()
#10 phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php(266): PHPUnit\Framework\TestSuite->run()
#11 phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php(44): PHPUnit\Framework\TestSuite->run()
#12 phar:///usr/local/bin/phpunit/phpunit/TextUI/Application.php(144): PHPUnit\TextUI\TestRunner->run()
#13 /usr/local/bin/phpunit(2976): PHPUnit\TextUI\Application->run()
#14 {main}
When I run with assertions being active, I get
Message: assert($this->currentTestCase !== null)
How to reproduce
Expected behavior
PHPUnit runs without internal error or documentation disallows assertions in setUp.
The text was updated successfully, but these errors were encountered: