Skip to content

Latest commit

 

History

History
83 lines (53 loc) · 2.52 KB

File metadata and controls

83 lines (53 loc) · 2.52 KB

Useful Resources & Extensions

Behat Extensions

There are a wide range of extensions already available. These include integrations with common PHP application frameworks, browser automation, test result reporters, data fixtures and many more.

We do not currently maintain an official list of extensions - most extensions can be found on GitHub.

Integrating Behat with PHPStorm

More information on integrating Behat with PHPStorm can be found in this blog post.

Assertion tools

A proper assertion tool is a library whose assertions throw exceptions on failure.

For example a list of the most known:

Caution with PHPUnit

If you are familiar with PHPUnit, you can use its assertion library

$ php composer.phar require --dev phpunit/phpunit

and then by simply using assertions in your steps:

\PHPUnit\Framework\Assert::assertCount(
    intval($count),
    $this->basket
);

WARNING: using PHPUnit for assertions no longer works with PHP 11.3.0 and later out-of-the-box.

This is due to a change in how PHPUnit's internal components are initialized. The recommended workaround to use the PHPUnit assertions is to bootstrap PHPUnit during Behat execution from a BeforeSuite hook:

use Behat\Hook\BeforeSuite;

class FeatureContext {

    #[BeforeSuite]
    public static function initPhpunit() {
        (new \PHPUnit\TextUI\Configuration\Builder())->build([]);
    }
}

If you have multiple suites, you may want to use a static variable in the hook to ensure the initialization only runs once.

Learn more at Behat/Behat#1618.

Behat cheat sheet

An interesting Behat and Mink cheat sheet developed by Jean-François Lépine