You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mnocon
changed the title
PHPUnit 10 Assertions failure results in "Uncaught Error: Class "PHPUnit\Framework\TestFailure" not found"
PHPUnit 10 Assertion failure results in "Uncaught Error: Class "PHPUnit\Framework\TestFailure" not found"
Feb 8, 2023
Hey, I saw the merged PR and I have a few follow up questions:
since it has been merged, shouldn't this ticket be closed (if the problem is now solved)?
looking at the code of the PR, I disagree a bit on how it works:
In my understanding, PHPUnitExceptionStringer->supportsException should have prevented the original problem from happening, so I would recommend looking into why it wasn't
The code of PHPUnitExceptionStringer->stringException is now a bit messier.. "if class exists return x; if class does not exist return z; else it must exist and therefore return y..", IMHO this would be clearer and more readable:
switch (true) {
case class_exists('PHPUnit\\Util\\ThrowableToStringMapper'):
return trim(\PHPUnit\Util\ThrowableToStringMapper::map($exception));
case class_exists('PHPUnit\\Framework\\TestFailure'):
// PHPUnit assertion exceptions do not include expected / observed info in their// messages, but expect the test listeners to format that info like the following// (see e.g. PHPUnit_TextUI_ResultPrinter::printDefectTrace)return trim(\PHPUnit\Framework\TestFailure::exceptionToString($exception));
case class_exists('PHPUnit_Framework_TestFailure'):
return trim(\PHPUnit_Framework_TestFailure::exceptionToString($exception));
default:
// TODO this should also be somehow handled
}
It now also exposes the original flaw, which the patch didn't fix adequately IMO.
Shouldn't PHPUnitExceptionStringer->supportsException also be updated to handle the new formatter?
Hi!
When a PHPUnit assertion fails in a Behat Context class the tests fail with:
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
The text was updated successfully, but these errors were encountered: