Skip to content

Conversation

@loru88
Copy link

@loru88 loru88 commented Nov 5, 2025

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

@loru88 loru88 force-pushed the v3.x branch 4 times, most recently from 5231115 to ed50aa4 Compare November 5, 2025 22:46
Copy link
Contributor

@acoulton acoulton left a 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`
Copy link
Contributor

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:

Suggested change
Learn more in the paragraph :ref:`assertion-tools`
Learn more about :ref:`assertion-tools`.

Comment on lines +57 to +65
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([]);
}
Copy link
Contributor

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_PATH const 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-run you won't have the overhead of phpunit booting for no reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHPUnit assertions cannot be used independently since 11.3.0

3 participants