diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 06cc506e670c..cffe00c750f7 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -267,7 +267,7 @@ private function parseDefinition($id, $service, $file) foreach ($service['tags'] as $tag) { if (!is_array($tag)) { - throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file)); + $tag = array('name' => $tag); } if (!isset($tag['name'])) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/badtag4.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/badtag4.yml deleted file mode 100644 index e8e99395b1fd..000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/badtag4.yml +++ /dev/null @@ -1,6 +0,0 @@ -services: - foo_service: - class: FooClass - tags: - # tag is not an array - - foo diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tag_name_only.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tag_name_only.yml new file mode 100644 index 000000000000..90180b0bb936 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/tag_name_only.yml @@ -0,0 +1,5 @@ +services: + foo_service: + class: FooClass + tags: + - foo diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index fabaa4859c57..89c2e4bf88a1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -223,16 +223,6 @@ public function testNonArrayTagsThrowsException() } } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException - * @expectedExceptionMessage A "tags" entry must be an array for service - */ - public function testNonArrayTagThrowsException() - { - $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); - $loader->load('badtag4.yml'); - } - public function testTagWithoutNameThrowsException() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); @@ -245,6 +235,15 @@ public function testTagWithoutNameThrowsException() } } + public function testNameOnlyTagsAreAllowedAsString() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('tag_name_only.yml'); + + $this->assertCount(1, $container->getDefinition('foo_service')->getTag('foo')); + } + public function testTagWithAttributeArrayThrowsException() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));