Skip to content

Commit 2123e78

Browse files
committed
Test service with factory is not tagged
1 parent 9a46529 commit 2123e78

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Tests/Fixtures/BarFactory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class BarFactory
6+
{
7+
/**
8+
* @var iterable
9+
*/
10+
private $bars;
11+
12+
public function __construct(iterable $bars)
13+
{
14+
$this->bars = \iterator_to_array($bars);
15+
}
16+
17+
public function getDefaultBar(): BarInterface
18+
{
19+
return reset($this->bars);
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
_instanceof:
3+
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
4+
tags:
5+
- { name: bar }
6+
7+
Symfony\Component\DependencyInjection\Tests\Fixtures\Bar:
8+
public: true
9+
10+
Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory:
11+
arguments: [!tagged 'bar']
12+
13+
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
14+
factory: ['@Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory', 'getDefaultBar']

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,4 +770,15 @@ public function testFqcnLazyProxy()
770770
$definition = $container->getDefinition('foo');
771771
$this->assertSame([['interface' => 'SomeInterface']], $definition->getTag('proxy'));
772772
}
773+
774+
public function testServiceWithSameNameAsInterfaceAndFactoryIsNotTagged()
775+
{
776+
$container = new ContainerBuilder();
777+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
778+
$loader->load('service_instanceof_factory.yml');
779+
$container->compile();
780+
781+
$tagged = $container->findTaggedServiceIds('bar');
782+
$this->assertCount(1, $tagged);
783+
}
773784
}

0 commit comments

Comments
 (0)