diff --git a/Command/LoadDataFixturesDoctrineODMCommand.php b/Command/LoadDataFixturesDoctrineODMCommand.php index 3ff670e5..1508ab28 100644 --- a/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/Command/LoadDataFixturesDoctrineODMCommand.php @@ -97,7 +97,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $loader = new ContainerAwareLoader($this->getContainer()); + $loaderClass = $this->getContainer()->getParameter('doctrine_mongodb.odm.fixture_loader'); + $loader = new $loaderClass($this->getContainer()); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($path); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ea952128..65023591 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -47,6 +47,13 @@ public function getConfigTreeBuilder() ->scalarNode('hydrator_namespace')->defaultValue('Hydrators')->end() ->scalarNode('hydrator_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators')->end() ->scalarNode('auto_generate_hydrator_classes')->defaultValue(false)->end() + ->scalarNode('fixture_loader') + ->defaultValue('Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader') + ->beforeNormalization() + ->ifTrue(function($v) {return !($v == 'Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader' || in_array('Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader', class_parents($v)));}) + ->then(function($v) { throw new \LogicException(sprintf("The %s class is not a subclass of the ContainerAwareLoader", $v));}) + ->end() + ->end() ->scalarNode('default_document_manager')->end() ->scalarNode('default_connection')->end() ->scalarNode('default_database')->defaultValue('default')->end() diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index ee25c59b..8ddb6c91 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -61,6 +61,9 @@ public function load(array $configs, ContainerBuilder $container) // set some options as parameters and unset them $config = $this->overrideParameters($config, $container); + // set the fixtures loader + $container->setParameter('doctrine_mongodb.odm.fixture_loader', $config['fixture_loader']); + // load the connections $this->loadConnections($config['connections'], $container); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 34f1b3a1..a397008b 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -28,6 +28,7 @@ public function testDefaults() $options = $processor->processConfiguration($configuration, array()); $defaults = array( + 'fixture_loader' => 'Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader', 'auto_generate_hydrator_classes' => false, 'auto_generate_proxy_classes' => false, 'default_database' => 'default', @@ -54,6 +55,7 @@ public function testFullConfiguration($config) $options = $processor->processConfiguration($configuration, array($config)); $expected = array( + 'fixture_loader' => 'Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader', 'auto_generate_hydrator_classes' => true, 'auto_generate_proxy_classes' => true, 'default_connection' => 'conn1', @@ -440,4 +442,29 @@ public function testInvalidReplicaSetValue() $configuration = new Configuration(false); $processor->processConfiguration($configuration, array($config)); } + + /** + * @dataProvider provideExceptionConfiguration + */ + public function testFixtureLoaderValidation($config) + { + $processor = new Processor(); + $configuration = new Configuration(false); + $this->setExpectedException('\LogicException'); + $processor->processConfiguration($configuration, array($config)); + } + + public function provideExceptionConfiguration() + { + $yaml = Yaml::parse(file_get_contents(__DIR__.'/Fixtures/config/yml/exception.yml')); + $yaml = $yaml['doctrine_mongodb']; + + $xml = XmlUtils::loadFile(__DIR__.'/Fixtures/config/xml/exception.xml'); + $xml = XmlUtils::convertDomElementToArray($xml->getElementsByTagName('config')->item(0)); + + return array( + array($yaml), + array($xml), + ); + } } diff --git a/Tests/DependencyInjection/Fixtures/config/xml/exception.xml b/Tests/DependencyInjection/Fixtures/config/xml/exception.xml new file mode 100644 index 00000000..07d4ed12 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/exception.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/Tests/DependencyInjection/Fixtures/config/xml/full.xml b/Tests/DependencyInjection/Fixtures/config/xml/full.xml index 6defab8b..e298cb40 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/full.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/full.xml @@ -7,6 +7,7 @@ http://symfony.com/schema/dic/doctrine/odm/mongodb http://symfony.com/schema/dic/doctrine/odm/mongodb/mongodb-1.0.xsd">