How do I overwrite the Symfony2 semantic configuration per environment?

后端 未结 3 1872
悲&欢浪女
悲&欢浪女 2021-01-21 07:16

parameters.yml:

time_limit:        8

my_ui.yml:

my_ui:
    time_limit: %time_limit%

config.yml:



        
相关标签:
3条回答
  • 2021-01-21 07:41

    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.

    0 讨论(0)
  • 2021-01-21 07:50

    The best way I found is setting up your own functional test environment for testing. This is completely seperated from your prod / dev environment.

    You can study nice examplse of this approach in Johann Schmidts bundles. I copied and adapted the one from the JMSPaymentCoreBundle for my projects.

    An other approach is to include (and override prod and dev settings) int he config_test.yml file. This file should be loaded by the test client only.

    0 讨论(0)
  • 2021-01-21 07:52

    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.

    0 讨论(0)
提交回复
热议问题