-
Notifications
You must be signed in to change notification settings - Fork 71
update to tell PHPUnit assertions stopped working #208
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
base: v3.x
Are you sure you want to change the base?
Conversation
5231115 to
ed50aa4
Compare
acoulton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loru88 thanks very much for this and apologies I missed it till now.
I approved the workflows which showed a couple of lint issues, however I also have a couple of small comments / suggestions.
| $this->basket | ||
| ); | ||
| tool out there. | ||
| Learn more in the paragraph :ref:`assertion-tools` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest more like:
| Learn more in the paragraph :ref:`assertion-tools` | |
| Learn more about :ref:`assertion-tools`. |
| However, a workaround exists by modifying the PHPUnit bootstrap file (in Symfony is usually at `tests/bootstrap.php`) | ||
| to explicitly initialize the PHPUnit configuration when running Behat. | ||
| This involves adding the following lines to your bootstrap file: | ||
|
|
||
| .. code-block:: php | ||
| if (defined('BEHAT_BIN_PATH')) { | ||
| (new \PHPUnit\TextUI\Configuration\Builder())->build([]); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest instead describing / showing an example doing this in a BeforeSuite hook e.g. more like:
use Behat\Hook\BeforeSuite;
class FeatureContext {
#[BeforeSuite]
public static function initPhpunit() {
// If you have multiple suites, you may want to use a static variable to ensure this only runs once.
(new \PHPUnit\TextUI\Configuration\Builder())->build([]);
}
}That has a few advantages:
- It is guaranteed to work in the same place in any Behat project (e.g. doesn't depend on the path to a bootstrap file).
- It doesn't depend on the
BEHAT_BIN_PATHconst which is arguably not part of our public API - I wouldn't expect it to change, but if it did it would be hard to understand what had broken. - It inits phpunit much later, nearer the point it might actually be required. So for example if you're running other behat commands or things like
--dry-runyou won't have the overhead of phpunit booting for no reason.
I updated the docs to let people be aware of this issue with PHPUnit 11.3
I linked to some alternative libraries and I added a workaround about how to make it work, but feel free to suggest a better description.
resolve Behat/Behat#1618