Codeception: Cannot use environment variables for Codeception config

Created on 21 Aug 2016  路  2Comments  路  Source: Codeception/Codeception

I am using Homestead to develop and I am trying to setup Codeship to run all Codeception tests. I need to use environment variables in the Codeception config for database user and password (and maybe other configs in the future).

I am trying to add the following code in the _bootstrap.php

\Codeception\Configuration::$defaultSuiteSettings['modules']['config'] = [
     'Db' => [
        'dsn' => 'mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_DATABASE'),
        'user' => getenv('DB_USERNAME'),
        'password' => getenv('DB_PASSWORD'),
        'dump' => '_data/dump.sql',
        'populate' => true,
        'cleanup' => true
    ]
];

but I get this error:

[Codeception\Exception\ModuleException]                                                                                           
  Db: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known while creating PDO connection

I also tried hardcoding the values, but still no luck. It's like _bootstrap.php is not even loaded. When I try to var_dump a get_env variable, I get false.

  • Codeception version: 2.2.3
  • PHP Version: 7.0
  • Operating System: Ubuntu
  • Installation type: Composer

Most helpful comment

Updated link:
http://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Parameters

All 2 comments

Ok, turned out I am just stupid. I found the page in the documentation that explains how to use environment variables in the Codeception config file. If anyone is interested, here's how it's done:

http://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Params

Updated link:
http://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Parameters

Was this page helpful?
0 / 5 - 0 ratings