“service_name”下无法识别的选项“service_name” - Symfony2配置构建器

时间:2013-03-07 13:58:18

标签: testing symfony bundle

我正在尝试在我的捆绑包中测试配置构建器:

这是我的DependencyInjection / Configuration.php

class Configuration implements ConfigurationInterface
{
    /**
     * Generates the configuration tree.
     *
     * @return TreeBuilder
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('product_viewer');

        $supportedDrivers = array('REST', 'SOAP');

        $rootNode->children()
            ->arrayNode('car')
                ->children()
                    ->scalarNode('webservice_type')
                        ->validate()
                            ->ifNotInArray($supportedDrivers)
                            ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
                        ->end()                
                    ->end()                
                    ->scalarNode('rest_url')->end()
                ->end()
            ->end();                

        return $treeBuilder;
    }
}

我的测试:

 /**
  * @test
  */
public function fullCondig() {
    $extension = new ProductCalculatorExtension();
    $config = $this->loadConfig('config1'); //this method only load yaml from file and parse it 
    $extension->load(array($config), new ContainerBuilder());
}

和测试配置看起来像:

product_viewer:
    car : 
        webservice_type : REST
        rest_url: 'example.com'
不幸的是,我得到的每一项测试都是:

  

的Symfony \元器件\配置\定义\异常\ InvalidConfigurationException:   “product_viewer”下无法识别的选项“product_viewer”

我不知道这里可能出现什么问题?

0 个答案:

没有答案