Behat / Symfony2Extension

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

Environment variable not found: "DATABASE_URL". #159

Open ahmedtoolapp opened 4 years ago

ahmedtoolapp commented 4 years ago

I am using Symfony2Extension with a new installation of Symfony 5.1 with PHP 7.3 I tried to launch vendor/bin/behat

I have my feature displayed but with an error

In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_URL".
kadzany commented 4 years ago

Have you solved this issue @ahmedtoolapp ?

mtarld commented 4 years ago

This error means that the bootstrap file isn't loaded. Indeed, the boostrap.php is responsible to load the Symfony's DotEnv component.

Therefore, have a look at your behat.yml file and make sure that the bootstrap file path is correctly configured.

Eg:

extensions:
    Behat\Symfony2Extension:
        kernel:
            bootstrap: features/bootstrap/bootstrap.php
            class: App\Kernel
denys999 commented 3 years ago

@ And how to connect Database ? How it looks like in FeatureContext ? function () { new Kernel ....

mrmkrs commented 7 months ago

For what it's worth, I've stumbled upon this issue too and using the comment of @mtarld I got it fixed (I was working on a symfony 6.4 to symfony 7 upgrade)

The error

In EnvVarProcessor.php line 217:

  [Symfony\Component\DependencyInjection\Exception\EnvNotFoundException]  
  Environment variable not found: "MYSQL_HOST".                           

The fix

        FriendsOfBehat\SymfonyExtension:
-            path: src/App/Kernel.php
+            path: tests/bootstrap.php

contents of bootstrap.php

<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
    require dirname(__DIR__).'/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
    (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
}