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