Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I overwrite the Symfony2 semantic configuration per environment?

Tags:

symfony

parameters.yml:

time_limit:        8

my_ui.yml:

my_ui:
    time_limit: %time_limit%

config.yml:

imports:
    - { resource: my_ui.yml }

I can then access this fine in my controller via the Extension and Configuration classes in my bundle.

How do I now overwrite the time_limit in my test environment?

I've tried loading another my_ui_test.yml in the config_test.yml file but to no avail.

like image 737
Tjorriemorrie Avatar asked Nov 26 '25 16:11

Tjorriemorrie


2 Answers

Figured it out: you must have one parameters file per host. But I need different parameters per env on one host.

parameters.yml:

parameters:
    time_limit: 8

my_ui.yml:

my_ui:
    time_limit: %time_limit%

config.yml:

imports:
    - { resource: my_ui.yml }

That gives me 8 in dev env.

Then, parameters_test.yml:

parameters:
    time_limit: 0

config_test.yml:

imports:
    - { resource: parameters_test.yml }

That gives me 0 in test env.

like image 150
Tjorriemorrie Avatar answered Nov 28 '25 09:11

Tjorriemorrie


Override any parameter in your config_test.yml file and make sure you make requests to the app_test.php controller when executing functional tests. If that controller doesn't exist, copy it from app_dev.php changing

$kernel = new AppKernel('dev', true);

to

$kernel = new AppKernel('test', true);

For example, I use the bcrypt password encoder that causes passwords to be encoded in 1-2 seconds each time. This is not acceptable for tests, so I override the cost to the minimal value in config_test.yml to speed up tests:

security:
    encoders:
        Elnur\Model\User:
            algorithm: bcrypt
            cost: 4

This way in production the cost would be 14, but in testing just 4.

like image 34
Elnur Abdurrakhimov Avatar answered Nov 28 '25 11:11

Elnur Abdurrakhimov