Skip to content

Commit 48dd4f9

Browse files
committed
Add test and use ternary operator
1 parent a017641 commit 48dd4f9

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,9 @@ private function parseDefinition($id, $service, $file, array $defaults)
331331
}
332332
}
333333

334-
if (isset($service['tags'])) {
335-
$tags = $service['tags'];
336-
337-
if (!is_array($tags)) {
338-
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
339-
}
340-
} else {
341-
$tags = array();
334+
$tags = isset($service['tags']) ? $service['tags'] : array();
335+
if (!is_array($tags)) {
336+
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
342337
}
343338

344339
if (!isset($defaults['tags'])) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
_defaults:
3+
tags: ['foo']
4+
5+
Foo\Bar:
6+
tags: invalid
7+
inherit_tags: true

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_configurator_short_syntax.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
services:
2-
32
foo_bar:
43
class: FooBarClass
54
configurator: foo_bar_configurator:configure

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,14 @@ public function testDecoratedServicesWithWrongSyntaxThrowsException()
408408
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
409409
$loader->load('bad_decorates.yml');
410410
}
411+
412+
/**
413+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
414+
* @expectedExceptionMessage Parameter "tags" must be an array for service "Foo\Bar" in services29_invalid_tags.yml. Check your YAML syntax.
415+
*/
416+
public function testInvalidTagsWithDefaults()
417+
{
418+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
419+
$loader->load('services31_invalid_tags.yml');
420+
}
411421
}

0 commit comments

Comments
 (0)