|
21 | 21 | use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
22 | 22 | use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
23 | 23 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 24 | +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
24 | 25 | use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
|
25 | 26 | use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
26 | 27 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
@@ -159,6 +160,7 @@ public function testLoadServices()
|
159 | 160 | $this->assertEquals([new Reference('baz'), 'getClass'], $services['new_factory2']->getFactory(), '->load() parses the factory tag');
|
160 | 161 | $this->assertEquals(['BazClass', 'getInstance'], $services['new_factory3']->getFactory(), '->load() parses the factory tag');
|
161 | 162 | $this->assertSame([null, 'getInstance'], $services['new_factory4']->getFactory(), '->load() accepts factory tag without class');
|
| 163 | + $this->assertEquals([new Reference('baz'), '__invoke'], $services['new_factory5']->getFactory(), '->load() accepts service reference as invokable factory'); |
162 | 164 | $this->assertEquals(['foo', new Reference('baz')], $services['Acme\WithShortCutArgs']->getArguments(), '->load() parses short service definition');
|
163 | 165 |
|
164 | 166 | $aliases = $container->getAliases();
|
@@ -197,6 +199,16 @@ public function testLoadFactoryShortSyntax()
|
197 | 199 |
|
198 | 200 | $this->assertEquals([new Reference('baz'), 'getClass'], $services['factory']->getFactory(), '->load() parses the factory tag with service:method');
|
199 | 201 | $this->assertEquals(['FooBacFactory', 'createFooBar'], $services['factory_with_static_call']->getFactory(), '->load() parses the factory tag with Class::method');
|
| 202 | + $this->assertEquals([new Reference('factory'), '__invoke'], $services['invokable_factory']->getFactory(), '->load() parses string service reference'); |
| 203 | + } |
| 204 | + |
| 205 | + public function testFactorySyntaxError() |
| 206 | + { |
| 207 | + $container = new ContainerBuilder(); |
| 208 | + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); |
| 209 | + $this->expectException(InvalidArgumentException::class); |
| 210 | + $this->expectExceptionMessage('The value of the "factory" option for the "invalid_factory" service must be the id of the service without the "@" prefix (replace "@factory:method" with "factory:method").'); |
| 211 | + $loader->load('bad_factory_syntax.yml'); |
200 | 212 | }
|
201 | 213 |
|
202 | 214 | public function testLoadConfiguratorShortSyntax()
|
|
0 commit comments