Behat with Symfony 7 is not as straight forward as it was for previous versions. To make it work properly, you need to know some things.
It may feel natural for some, but not for all I'm sure. So here is my first advise: use the Symfony extension.
It's super simple:
composer require --dev friends-of-behat/symfony-extension
Basically, your behat install will work out of the box with the Symfony cli (symfony php ./vendor/bin/behat
). If you do not want to use it to run behat, you will need to add a custom bootstrap.
So in your behat.yml.dist
file, add the following:
default:
extensions:
FriendsOfBehat\SymfonyExtension:
bootstrap: config/bootstrap_test.php
And in the file config/bootstrap_test.php
, just run dotenv to be sure your environment is setup properly!
<?php
declare(strict_types=1);
// Enforce test environment
$_SERVER['APP_ENV'] = 'test';
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
$dotenv = new Dotenv();
$dotenv->loadEnv(dirname(__DIR__).'/.env');
You can now run Behat without issues!