为什么我的配置没有被 symfony2 中的测试环境覆盖?
Why isn't my configuraton overwritten for the test environment in symfony2?
我有一个 symfony2 应用程序,它需要针对某些环境进行不同的配置设置,例如test
.
我像这样覆盖我的 config.yml 测试环境:
AppKernel.php
:
public function registerContainerConfiguration(LoaderInterface $loader)
{
foreach ($this->getBundles() as $bundle) {
if (false === strpos($bundle->getName(), 'Dreamlines')) {
continue;
}
$configFile = $bundle->getPath() . '/Resources/config/config.yml';
if (!file_exists($configFile)) {
continue;
}
$loader->load($configFile);
}
$loader->load(__DIR__ . '/config/config_' . $this->getEnvironment() . '.yml');
}
在我的config.yml
中我定义:
default_airports:
cun:
de:
- FRA
在我的 config_test.yml 中,我定义了以下内容来覆盖值:
default_airports:
cun:
de:
- HAM
我的 ConfigTreeBuilder 寻找配置看起来像
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder
->root('le_bundle');
$rootNode
...
->arrayNode('default_airports')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->prototype('array')
->prototype('scalar')->end()
->end()
->end()
->end()
然而配置没有被正确覆盖,导致测试 运行 失败。
这是怎么回事?我已经使用此策略成功重写了其他配置条目。
在每个环境的文件中比较 default_airports
时:
app/cache/dev/appDevDebugProjectContainer.php
app/cache/test/appTestDebugProjectContainer.php
数组丢失了它的键,而不是预期的
`de` => arrray(0 => 'HAM')
有一个索引为 0 的数组。
因此 Configuration.php
中 ConfigTreeBuilder
的相关部分必须如下所示:
->arrayNode('default_airports')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->useAttributeAsKey('name') // FIXES LOST KEY IN CONFIG FOR TEST ENV
->prototype('array')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->end()
我有一个 symfony2 应用程序,它需要针对某些环境进行不同的配置设置,例如test
.
我像这样覆盖我的 config.yml 测试环境:
AppKernel.php
:
public function registerContainerConfiguration(LoaderInterface $loader)
{
foreach ($this->getBundles() as $bundle) {
if (false === strpos($bundle->getName(), 'Dreamlines')) {
continue;
}
$configFile = $bundle->getPath() . '/Resources/config/config.yml';
if (!file_exists($configFile)) {
continue;
}
$loader->load($configFile);
}
$loader->load(__DIR__ . '/config/config_' . $this->getEnvironment() . '.yml');
}
在我的config.yml
中我定义:
default_airports:
cun:
de:
- FRA
在我的 config_test.yml 中,我定义了以下内容来覆盖值:
default_airports:
cun:
de:
- HAM
我的 ConfigTreeBuilder 寻找配置看起来像
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder
->root('le_bundle');
$rootNode
...
->arrayNode('default_airports')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->prototype('array')
->prototype('scalar')->end()
->end()
->end()
->end()
然而配置没有被正确覆盖,导致测试 运行 失败。
这是怎么回事?我已经使用此策略成功重写了其他配置条目。
在每个环境的文件中比较 default_airports
时:
app/cache/dev/appDevDebugProjectContainer.php
app/cache/test/appTestDebugProjectContainer.php
数组丢失了它的键,而不是预期的
`de` => arrray(0 => 'HAM')
有一个索引为 0 的数组。
因此 Configuration.php
中 ConfigTreeBuilder
的相关部分必须如下所示:
->arrayNode('default_airports')
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->useAttributeAsKey('name') // FIXES LOST KEY IN CONFIG FOR TEST ENV
->prototype('array')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->end()