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
Copy file name to clipboardExpand all lines: useful_resources.rst
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,58 @@ Integrating Behat with PHPStorm
18
18
More information on integrating Behat with PHPStorm can be found in this
19
19
`blog post`_.
20
20
21
+
.. _assertion-tools:
22
+
23
+
Assertion tools
24
+
---------------
25
+
26
+
A proper assertion tool is a library whose assertions throw exceptions on failure.
27
+
28
+
For example a list of the most known:
29
+
30
+
- https://github.com/webmozarts/assert
31
+
- https://github.com/beberlei/assert
32
+
- https://github.com/zenstruck/assert
33
+
34
+
.. caution::
35
+
If you are familiar with PHPUnit, you can use its assertion library
36
+
37
+
.. code-block:: bash
38
+
39
+
$ php composer.phar require --dev phpunit/phpunit
40
+
41
+
and then by simply using assertions in your steps:
42
+
43
+
.. code-block:: php
44
+
45
+
\PHPUnit\Framework\Assert::assertCount(
46
+
intval($count),
47
+
$this->basket
48
+
);
49
+
50
+
**However, using PHPUnit for assertions no longer works with PHP 11.3.0 and later**.
51
+
52
+
This is due to a change in how PHPUnit's internal components are initialized.
53
+
A direct alternative that provides a complete object and array comparison is not readily available.
54
+
55
+
Learn more at https://github.com/Behat/Behat/issues/1618.
56
+
57
+
However, a workaround exists by modifying the PHPUnit bootstrap file (tests/bootstrap.php) to explicitly initialize the PHPUnit configuration when running Behat.
58
+
This involves adding the following lines to your bootstrap file:
59
+
60
+
.. code-block:: php
61
+
62
+
if (defined('BEHAT_BIN_PATH')) {
63
+
(new \PHPUnit\TextUI\Configuration\Builder())->build([]);
64
+
}
65
+
66
+
This is a hack that forces PHPUnit to load its necessary components.
67
+
The downside is that it creates a tight coupling between your project and PHPUnit's internal, non-public API.
68
+
This makes the workaround brittle and prone to breaking with future updates to either framework.
69
+
Furthermore, it forces the entire PHPUnit framework to be bootstrapped along with Behat, which results in a larger memory footprint
70
+
and slightly slower execution of your tests. This makes your test setup less portable and harder to maintain.
0 commit comments