11

我无法找到一种方法来security.yml包含根据 Symfony2 的环境而包含的不同文件。例如,我想为我的验收测试提供一个内存用户提供程序,因为我真的不需要在这里测试我的实体和东西,我只想对我的视图进行验收测试。

但是,事实证明,这并不是一件容易的事。我security.yml从我的包含中删除config.yml,将其重命名为security_prod.yml并创建了一个security_test.yml包含in_memory用户提供程序的内容。然后我分别在我的生产和测试配置中包含security_prod.yml和。security_test.yml

然而它似乎根本不起作用:

$ SYMFONY_ENV=test app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]                                                           
  You are not allowed to define new elements for path "security.providers". Please define all elements for this path in one config file.  

$ SYMFONY_ENV=prod app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException]                                                                         
  Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one   
  configuration section.                                                                                                                              

在我看来,security.yml文件名是硬编码的(这对 Symfony 来说太奇怪了),但事实并非如此。

所以问题是:如何security.yml使用 Symfony 获得多个 s?什么可能导致这种行为?

4

1 回答 1

4

给正在寻找它的人的说明(不要红色评论):

  1. 为不同的环境创建不同config的文件:config_test.yml, config_dev.yml,config_prod.yml
  2. 创建不同的security文件:security_test.yml, security_dev.yml,security_prod.yml
  3. security_test.yml其他环境的导入 config_test.yml等等。示例config_test.yml

    imports:
      - { resource: security_test.yml }
    
  4. 确保您security_*.yml只包含一次(基本上作者犯了这个错误)
于 2017-01-12T08:47:37.877 回答