Test service with factory is not tagged

This commit is contained in:
Maciej Malarz 2019-03-25 22:20:26 +01:00
parent 2d2cd40ba6
commit a8e9f4092c
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
class BarFactory
{
/**
* @var iterable
*/
private $bars;
public function __construct(iterable $bars)
{
$this->bars = \iterator_to_array($bars);
}
public function getDefaultBar(): BarInterface
{
return reset($this->bars);
}
}

View File

@ -0,0 +1,14 @@
services:
_instanceof:
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
tags:
- { name: bar }
Symfony\Component\DependencyInjection\Tests\Fixtures\Bar:
public: true
Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory:
arguments: [!tagged 'bar']
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
factory: ['@Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory', 'getDefaultBar']

View File

@ -770,4 +770,15 @@ class YamlFileLoaderTest extends TestCase
$definition = $container->getDefinition('foo');
$this->assertSame([['interface' => 'SomeInterface']], $definition->getTag('proxy'));
}
public function testServiceWithSameNameAsInterfaceAndFactoryIsNotTagged()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('service_instanceof_factory.yml');
$container->compile();
$tagged = $container->findTaggedServiceIds('bar');
$this->assertCount(1, $tagged);
}
}