-
-
Notifications
You must be signed in to change notification settings - Fork 613
Description
Hi!
When a PHPUnit assertion fails in a Behat Context class the tests fail with:
~/Desktop/repos/behat-phpunit10 on main !2 ?2 ❯ vendor/bin/behat 14.17.0 at 10:36:00
Feature: PHPUnit 10 exception
Scenario: Trigger PHPUnitExceptionStringer # features/Reproducer.feature:3
Given ExceptionStringer is triggered # FeatureContext::triggerExceptionStringer()
PHP Fatal error: Uncaught Error: Class "PHPUnit\Framework\TestFailure" not found in /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Testwork/Exception/Stringer/PHPUnitExceptionStringer.php:49
Stack trace:
#0 /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Testwork/Exception/ExceptionPresenter.php(93): Behat\Testwork\Exception\Stringer\PHPUnitExceptionStringer->stringException(Object(PHPUnit\Framework\ExpectationFailedException), 1)
#1 /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyStepPrinter.php(174): Behat\Testwork\Exception\ExceptionPresenter->presentException(Object(PHPUnit\Framework\ExpectationFailedException))
#2 /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyStepPrinter.php(95): Behat\Behat\Output\Node\Printer\Pretty\PrettyStepPrinter->printException(Object(Behat\Testwork\Output\Printer\StreamOutputPrinter), Object(Behat\Behat\Tester\Result\ExecutedStepResult))
#3 /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Behat/Output/Node/EventListener/AST/StepListener.php(119): Behat\Behat\Output\Node\Printer\Pretty\PrettyStepPrinter->printStep(Object(Behat\Testwork\Output\NodeEventListeningFormatter), Object(Behat\Gherkin\Node\ScenarioNode), Object(Behat\Gherkin\Node\StepNode), Object(Behat\Behat\Tester\Result\ExecutedStepResult))
#4 /Users/mareknocon/Desktop/repos/behat-phpunit10/behat/src/Behat/Behat/Output/Node/EventListener/AST/StepListener.php(65): Behat\Behat\Output\Node\EventListener\AST\StepListener->printStepOnAfterEvent(Object(Behat\Testwork\Output\NodeEventListeningFormatter), Object(Behat\Behat\EventDispatcher\Event\AfterStepTested))
stopping the test execution.
I've created a reproducer for this issue, if you'd like to test it yourself:
https://github.com/mnocon/behat-phpunit10
PHPunit 9 used the TestFailure class to stringify an Exception:
https://github.com/sebastianbergmann/phpunit/blob/9.6/src/Framework/Exception/Exception.php#L58-L67
but in PHPUnit 10 ThrowableToStringMapper is responsible for that:
https://github.com/sebastianbergmann/phpunit/blob/10.0/src/Framework/Exception/Exception.php#L57-L69
(and the TestFailure class is gone).
I made an attempt at solving this, in #1422