|
12 | 12 | namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; |
15 | 16 | use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
16 | 17 | use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
| 18 | +use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; |
| 19 | +use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; |
17 | 20 | use Symfony\Component\DependencyInjection\Attribute\Target;
|
18 | 21 | use Symfony\Component\DependencyInjection\ChildDefinition;
|
19 | 22 | use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
@@ -460,10 +463,6 @@ public function testResponseArgumentIsIgnored()
|
460 | 463 |
|
461 | 464 | public function testAutowireAttribute()
|
462 | 465 | {
|
463 |
| - if (!class_exists(Autowire::class)) { |
464 |
| - $this->markTestSkipped('#[Autowire] attribute not available.'); |
465 |
| - } |
466 |
| - |
467 | 466 | $container = new ContainerBuilder();
|
468 | 467 | $resolver = $container->register('argument_resolver.service', 'stdClass')->addArgument([]);
|
469 | 468 |
|
@@ -493,6 +492,42 @@ public function testAutowireAttribute()
|
493 | 492 | $this->assertSame('foo', $locator->get('customAutowire'));
|
494 | 493 | $this->assertFalse($locator->has('service2'));
|
495 | 494 | }
|
| 495 | + |
| 496 | + public function testTaggedIteratorAndTaggedLocatorAttributes() |
| 497 | + { |
| 498 | + $container = new ContainerBuilder(); |
| 499 | + $resolver = $container->register('argument_resolver.service', \stdClass::class)->addArgument([]); |
| 500 | + |
| 501 | + $container->register('bar', \stdClass::class)->addTag('foobar'); |
| 502 | + $container->register('baz', \stdClass::class)->addTag('foobar'); |
| 503 | + |
| 504 | + $container->register('foo', WithTaggedIteratorAndTaggedLocator::class) |
| 505 | + ->addTag('controller.service_arguments'); |
| 506 | + |
| 507 | + (new RegisterControllerArgumentLocatorsPass())->process($container); |
| 508 | + |
| 509 | + $locatorId = (string) $resolver->getArgument(0); |
| 510 | + $container->getDefinition($locatorId)->setPublic(true); |
| 511 | + |
| 512 | + $container->compile(); |
| 513 | + |
| 514 | + /** @var ServiceLocator $locator */ |
| 515 | + $locator = $container->get($locatorId)->get('foo::fooAction'); |
| 516 | + |
| 517 | + $this->assertCount(2, $locator->getProvidedServices()); |
| 518 | + |
| 519 | + $this->assertTrue($locator->has('iterator')); |
| 520 | + $this->assertInstanceOf(RewindableGenerator::class, $argIterator = $locator->get('iterator')); |
| 521 | + $this->assertCount(2, $argIterator); |
| 522 | + |
| 523 | + $this->assertTrue($locator->has('locator')); |
| 524 | + $this->assertInstanceOf(ServiceLocator::class, $argLocator = $locator->get('locator')); |
| 525 | + $this->assertCount(2, $argLocator); |
| 526 | + $this->assertTrue($argLocator->has('bar')); |
| 527 | + $this->assertTrue($argLocator->has('baz')); |
| 528 | + |
| 529 | + $this->assertSame(iterator_to_array($argIterator), [$argLocator->get('bar'), $argLocator->get('baz')]); |
| 530 | + } |
496 | 531 | }
|
497 | 532 |
|
498 | 533 | class RegisterTestController
|
@@ -614,3 +649,12 @@ public function fooAction(
|
614 | 649 | ) {
|
615 | 650 | }
|
616 | 651 | }
|
| 652 | + |
| 653 | +class WithTaggedIteratorAndTaggedLocator |
| 654 | +{ |
| 655 | + public function fooAction( |
| 656 | + #[TaggedIterator('foobar')] iterable $iterator, |
| 657 | + #[TaggedLocator('foobar')] ServiceLocator $locator, |
| 658 | + ) { |
| 659 | + } |
| 660 | +} |
0 commit comments