-
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
Open
loru88
wants to merge
1
commit into
Behat:v3.x
Choose a base branch
from
loru88:v3.x
base: v3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,58 @@ Integrating Behat with PHPStorm | |
| More information on integrating Behat with PHPStorm can be found in this | ||
| `blog post`_. | ||
|
|
||
| .. _assertion-tools: | ||
|
|
||
| Assertion tools | ||
| --------------- | ||
|
|
||
| A proper assertion tool is a library whose assertions throw exceptions on failure. | ||
|
|
||
| For example a list of the most known: | ||
|
|
||
| - https://github.com/webmozarts/assert | ||
| - https://github.com/beberlei/assert | ||
| - https://github.com/zenstruck/assert | ||
|
|
||
| .. caution:: | ||
| If you are familiar with PHPUnit, you can use its assertion library | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ php composer.phar require --dev phpunit/phpunit | ||
|
|
||
| and then by simply using assertions in your steps: | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| \PHPUnit\Framework\Assert::assertCount( | ||
| intval($count), | ||
| $this->basket | ||
| ); | ||
|
|
||
| **However, using PHPUnit for assertions no longer works with PHP 11.3.0 and later**. | ||
|
|
||
| This is due to a change in how PHPUnit's internal components are initialized. | ||
| A direct alternative that provides a complete object and array comparison is not readily available. | ||
|
|
||
| Learn more at https://github.com/Behat/Behat/issues/1618. | ||
|
|
||
| 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([]); | ||
| } | ||
|
Comment on lines
+57
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest instead describing / showing an example doing this in a 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:
|
||
|
|
||
| This is a hack that forces PHPUnit to load the necessary components. | ||
| The downside is that it creates a tight coupling between your project and PHPUnit's internal non-public API | ||
| and it forces the entire PHPUnit framework to be bootstrapped along with Behat, which results in a larger memory footprint. | ||
| This makes the workaround brittle and prone to breaking with future updates. | ||
|
|
||
|
|
||
| Behat cheat sheet | ||
| ----------------- | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: