|
34 | 34 | use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; |
35 | 35 | use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException; |
36 | 36 | use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 37 | +use Symfony\Component\DependencyInjection\Exception\LogicException; |
37 | 38 | use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException; |
38 | 39 | use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; |
39 | 40 | use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
@@ -1065,47 +1066,61 @@ public function testMergeLogicException() |
1065 | 1066 | public function testFindTaggedServiceIds() |
1066 | 1067 | { |
1067 | 1068 | $builder = new ContainerBuilder(); |
1068 | | - $builder |
1069 | | - ->register('foo', 'Bar\FooClass') |
| 1069 | + $builder->register('foo', 'Bar\FooClass') |
1070 | 1070 | ->setAbstract(true) |
1071 | 1071 | ->addTag('foo', ['foo' => 'foo']) |
1072 | 1072 | ->addTag('bar', ['bar' => 'bar']) |
1073 | | - ->addTag('foo', ['foofoo' => 'foofoo']) |
1074 | | - ; |
1075 | | - $builder |
1076 | | - ->register('bar', 'Bar\FooClass') |
| 1073 | + ->addTag('foo', ['foofoo' => 'foofoo']); |
| 1074 | + $builder->register('bar', 'Bar\FooClass') |
1077 | 1075 | ->addTag('foo') |
1078 | | - ->addTag('container.excluded') |
1079 | | - ; |
| 1076 | + ->addTag('container.excluded'); |
| 1077 | + |
1080 | 1078 | $this->assertEquals([ |
1081 | 1079 | 'foo' => [ |
1082 | 1080 | ['foo' => 'foo'], |
1083 | 1081 | ['foofoo' => 'foofoo'], |
1084 | 1082 | ], |
1085 | 1083 | ], $builder->findTaggedServiceIds('foo'), '->findTaggedServiceIds() returns an array of service ids and its tag attributes'); |
| 1084 | + } |
| 1085 | + |
| 1086 | + public function testFindTaggedServiceIdsThrowsWhenAbstract() |
| 1087 | + { |
| 1088 | + $builder = new ContainerBuilder(); |
| 1089 | + $builder->register('foo', 'Bar\FooClass') |
| 1090 | + ->setAbstract(true) |
| 1091 | + ->addTag('foo', ['foo' => 'foo']); |
| 1092 | + |
1086 | 1093 | $this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services'); |
1087 | 1094 | $this->expectException(InvalidArgumentException::class); |
1088 | 1095 | $this->expectExceptionMessage('The service "foo" tagged "foo" must not be abstract.'); |
1089 | 1096 | $builder->findTaggedServiceIds('foo', true); |
1090 | 1097 | } |
1091 | 1098 |
|
1092 | | - public function testFindTaggedValueObjects() |
| 1099 | + public function testFindExcludedServiceIds() |
1093 | 1100 | { |
1094 | 1101 | $builder = new ContainerBuilder(); |
1095 | | - $builder |
1096 | | - ->register('foo', 'Bar\FooClass') |
| 1102 | + $builder->register('myservice', 'Bar\FooClass') |
1097 | 1103 | ->addTag('foo', ['foo' => 'foo']) |
1098 | 1104 | ->addTag('bar', ['bar' => 'bar']) |
1099 | 1105 | ->addTag('foo', ['foofoo' => 'foofoo']) |
1100 | | - ; |
| 1106 | + ->addExcludeTag('container.excluded'); |
| 1107 | + |
| 1108 | + $expected = ['myservice' => [['foo' => 'foo'], ['foofoo' => 'foofoo']]]; |
| 1109 | + $this->assertSame($expected, $builder->findExcludedServiceIds('foo')); |
| 1110 | + $this->assertSame([], $builder->findExcludedServiceIds('foofoo')); |
| 1111 | + } |
1101 | 1112 |
|
1102 | | - $expected = ['foo' => [['foo' => 'foo'], ['foofoo' => 'foofoo']]]; |
1103 | | - $this->assertSame($expected, $builder->findTaggedValueObjects('foo', false)); |
1104 | | - $this->assertFalse($builder->getDefinition('foo')->hasTag('container.excluded')); |
1105 | | - $this->assertFalse($builder->getDefinition('foo')->isAbstract()); |
1106 | | - $this->assertSame($expected, $builder->findTaggedValueObjects('foo')); |
1107 | | - $this->assertTrue($builder->getDefinition('foo')->hasTag('container.excluded')); |
1108 | | - $this->assertTrue($builder->getDefinition('foo')->isAbstract()); |
| 1113 | + public function testFindExcludedServiceIdsThrowsWhenNotExcluded() |
| 1114 | + { |
| 1115 | + $builder = new ContainerBuilder(); |
| 1116 | + $builder->register('myservice', 'Bar\FooClass') |
| 1117 | + ->addTag('foo', ['foo' => 'foo']) |
| 1118 | + ->addTag('bar', ['bar' => 'bar']) |
| 1119 | + ->addTag('foo', ['foofoo' => 'foofoo']); |
| 1120 | + |
| 1121 | + $this->expectException(InvalidArgumentException::class); |
| 1122 | + $this->expectExceptionMessage('The service "myservice" tagged "foo" must have the "container.excluded" tag.'); |
| 1123 | + $builder->findExcludedServiceIds('foo', true); |
1109 | 1124 | } |
1110 | 1125 |
|
1111 | 1126 | public function testFindUnusedTags() |
|
0 commit comments