4

我正在尝试在我的捆绑包中测试配置生成器:

这是我的 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\Component\Config\Definition\Exception\InvalidConfigurationException:“product_viewer”下无法识别的选项“product_viewer”

我不知道这里有什么问题?

4

0 回答 0