I added the \"if (defined('BEHAT_BIN_PATH'))\" because my bootstrap file is shared between Behat and PHPUnit and of course I don't want that to run when running PHPUnit suite because that is handled automatically by PHPUnit itself.
","upvoteCount":1,"url":"https://github.com/Behat/Behat/discussions/1617#discussioncomment-12748611"}}}-
hello, I'm using PHPUnit 11 and Behat 3.20. However, when an Assert fails it throws fatal error with such message: It's like if the Asserts try to get something from PHPUnit configuration when it has to report the failure description but it crashes because it can't access the PHPUnit configuration since it's outside of the PHPUnit context. My question is if I'm doing something wrong, or it's actually impossible to use PHPUnit asserts outside the PHPUnit context. |
Beta Was this translation helpful? Give feedback.
-
Hmmm, it looks like sebastianbergmann/phpunit#5869 released with PHPUnit 11.3.0 introduced a runtime dependency on the PHPUnit configuration object deep within the This means that as you say it's currently not possible to use PHPUnit assertions outside the PHPUnit runtime with PHPUnit >= 11.3.0 (this is not a Behat-specific thing). I have raised this as an issue on PHPUnit in the first instance to see what they say. |
Beta Was this translation helpful? Give feedback.
-
I think I found a workaround to make Assertion work properly in Behat. if (defined('BEHAT_BIN_PATH')) {
(new \PHPUnit\TextUI\Configuration\Builder())->build([]);
} I added the "if (defined('BEHAT_BIN_PATH'))" because my bootstrap file is shared between Behat and PHPUnit and of course I don't want that to run when running PHPUnit suite because that is handled automatically by PHPUnit itself. |
Beta Was this translation helpful? Give feedback.
I think I found a workaround to make Assertion work properly in Behat.
You have to define a bootstrap file and add this piece of code that will create the PHPUnit configuration only if executed in the Behat runtime:
I added the "if (defined('BEHAT_BIN_PATH'))" because my bootstrap file is shared between Behat and PHPUnit and of course I don't want that to run when running PHPUnit suite because that is handled automatically by PHPUnit itself.