Behat / Symfony2Extension

Symfony2 extension for Behat
MIT License
393 stars 106 forks source link

Support .env.test #146

Closed XavierVallot closed 5 years ago

XavierVallot commented 5 years ago

Hi, regarding the recent Symfony evolutions (https://symfony.com/doc/current/configuration/dot-env-changes.html#updating-my-application), do you plan to add support for .env.test file ? Thank you !

claudusd commented 5 years ago

Hi,

I think, this is already implemented. You should set the the bootstrap file path in your configuration. By default the bootstrap's path is app/autoload.php. Now the bootstrap's path is config/bootstrap.php

default:
  extensions:
    Behat\Symfony2Extension:
      kernel:
        bootstrap: config/bootstrap.php

The support of .env.* is provided by the new config.php.

kevin-lot commented 5 years ago

What about this file : https://github.com/symfony/recipes/blob/master/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php ?

Environment seems to be set to 'test'.

bootstrap.php

set 'APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test'

behat.yml.dist

default:
    extensions:
        Behat\Symfony2Extension:
            kernel:
                bootstrap: 'features/bootstrap/bootstrap.php'
                class: 'App\Kernel'
souhail-5 commented 5 years ago

Note that in Symfony 4, the .env.local file is not loaded when APP_ENV=test.

This can be embarrassing when you have declared your DATABASE_URL in .env.local and you want to use the database from a Behat Context.

If you want to keep the default env value of Behat (APP_ENV=test), you have to create 2 files, .env.test (committed) and .env.test.local (not committed), and declare on them your DATABASE_URL