diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index e7703aabf89a9..d84112d527316 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -205,7 +205,7 @@ private function parseDefinitions(array $content, $file) throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file)); } - if (isset($content['services']['_instanceof'])) { + if (array_key_exists('_instanceof', $content['services'])) { $instanceof = $content['services']['_instanceof']; unset($content['services']['_instanceof']); @@ -242,7 +242,7 @@ private function parseDefinitions(array $content, $file) */ private function parseDefaults(array &$content, $file) { - if (!isset($content['services']['_defaults'])) { + if (!array_key_exists('_defaults', $content['services'])) { return array(); } $defaults = $content['services']['_defaults']; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_defaults.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_defaults.yml new file mode 100644 index 0000000000000..85d910e3e31fb --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_defaults.yml @@ -0,0 +1,2 @@ +services: + _defaults: diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_instanceof.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_instanceof.yml new file mode 100644 index 0000000000000..2c8ce09ff6f3e --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_instanceof.yml @@ -0,0 +1,2 @@ +services: + _instanceof: diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 87a05eb2abd1f..a87619e03287b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -577,6 +577,28 @@ public function testAutoConfigureInstanceof() $this->assertTrue($container->getDefinition('use_defaults_settings')->isAutoconfigured()); $this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->isAutoconfigured()); } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Service "_defaults" key must be an array, "NULL" given in "bad_empty_defaults.yml". + */ + public function testEmptyDefaultsThrowsClearException() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('bad_empty_defaults.yml'); + } + + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Service "_instanceof" key must be an array, "NULL" given in "bad_empty_instanceof.yml". + */ + public function testEmptyInstanceofThrowsClearException() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('bad_empty_instanceof.yml'); + } } interface FooInterface