Local config for Codeception tests in Advanced application

I really like how the Advanced application template handles the configs and environments. It really helps when working in a team.

Unfortunately the configuration for Codeception tests isn’t structured in a same way. So unless some modifications are made absolute URLs and DB configs are stored in the repository.

I suppose I’m not the first one to run into this issue. Do you have any tips/best practices on how to handle the configuration of tests in an elegant way?

I would argue that it is structured similarly. Under tests/codeception/config you have a dir for backend, common, console and frontend. You can override things there in the same way as with the web app. It includes all the config files, eg here is the frontend/unit.php

So its easy to override things you want to change in the test environment, eg db settings


 * Application configuration for frontend unit tests


return yii\helpers\ArrayHelper::merge(

    require(YII_APP_BASE_PATH . '/common/config/main.php'),

    require(YII_APP_BASE_PATH . '/common/config/main-local.php'),

    require(YII_APP_BASE_PATH . '/frontend/config/main.php'),

    require(YII_APP_BASE_PATH . '/frontend/config/main-local.php'),

    require(dirname(__DIR__) . '/config.php'),

    require(dirname(__DIR__) . '/unit.php'),

    require(__DIR__ . '/config.php'),



To override for all tests, use codeception/config/config.php


return [

    'components' => [

        'db' => [

			'class' => 'yii\db\Connection',

			'dsn' => 'mysql:host=localhost;dbname=test',

			'username' => 'test',

			'password' => 'rtest',

			'charset' => 'utf8',


        'mailer' => [

            'useFileTransport' => true,


        'urlManager' => [

            'showScriptName' => true,




You are right that the structure is similar when it comes to separating frontend, backend, etc. What I meant is that the main application has global configs that are stored in the repository and local configs that are stored only locally. In tests codeception\config\config.php is already a part of the template, not the local file and there are also YML configs that contains absolute URLs.

I have the general idea how to modify the structure of tests in a similar way. I just wanted to check how others cope with it in their projects.

I think it would make sense to make the tests “repository-friendly” in the application itself but perhaps I’m missing some point so I rather opened this topic before posting feature suggestion.

I’ve added a poll to this topic. I’d be interested to know how you handle the discussed issue in your projects.

I’ve pointed out this issue on GitHub however it was found unessential (https://github.com/yiisoft/yii2/issues/7487).

Just in case somebody faces the same problem I’m posting my solution here:


[*]I moved YML configs used by codeception to the environments/dev/ to get them copied during the init. Also I marked them as untracked for the repository.

[*]I added config-local.php to tests/codeception/config/ to hold local params (DB connection etc.).

[*]Then I modified other configs to include the new config-local.php file.


I’ve committed these changes to a forked repository: https://github.com/VojtechH/yii2/commit/6bd34e5302ba5c487f908bef3ece9222db7c8c4c

I’d welcome any comments on my approach.