From 49fe3f4c2d248f594dd7b27fd8eedb36bce220ed Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 27 Apr 2017 22:24:58 -0400 Subject: [PATCH 1/3] Fixing problem where _defaults set to null was seen as a service This gives a better error message --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index e7703aabf89a9..7c4cd86f334d6 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -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']; From 76537b93d76521e4ec9fb1a99db7bb88d944ad9d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 28 Apr 2017 14:04:18 -0400 Subject: [PATCH 2/3] Adding a test --- .../Tests/Fixtures/yaml/bad_empty_defaults.yml | 2 ++ .../Tests/Loader/YamlFileLoaderTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_defaults.yml 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/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 87a05eb2abd1f..52869dc30c410 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -577,6 +577,17 @@ 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'); + } } interface FooInterface From bc56035e0748270f807d243a62845154b8e207ae Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 28 Apr 2017 14:26:00 -0400 Subject: [PATCH 3/3] Also catching bad _instanceof --- .../DependencyInjection/Loader/YamlFileLoader.php | 2 +- .../Tests/Fixtures/yaml/bad_empty_instanceof.yml | 2 ++ .../Tests/Loader/YamlFileLoaderTest.php | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_empty_instanceof.yml diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 7c4cd86f334d6..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']); 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 52869dc30c410..a87619e03287b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -588,6 +588,17 @@ public function testEmptyDefaultsThrowsClearException() $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