|
16 | 16 | use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
|
17 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
18 | 18 | use Symfony\Component\DependencyInjection\Tests\Fixtures\WitherStaticReturnType;
|
| 19 | +use Symfony\Contracts\Service\Attribute\Required; |
19 | 20 |
|
20 | 21 | require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php';
|
21 | 22 |
|
@@ -54,6 +55,29 @@ public function testSetterInjection()
|
54 | 55 | $this->assertEquals([], $methodCalls[1][1]);
|
55 | 56 | }
|
56 | 57 |
|
| 58 | + /** |
| 59 | + * @requires PHP 8 |
| 60 | + */ |
| 61 | + public function testSetterInjectionWithAttribute() |
| 62 | + { |
| 63 | + if (!class_exists(Required::class)) { |
| 64 | + $this->markTestSkipped('symfony/service-contracts 2.2 required'); |
| 65 | + } |
| 66 | + |
| 67 | + $container = new ContainerBuilder(); |
| 68 | + $container->register(Foo::class); |
| 69 | + |
| 70 | + $container |
| 71 | + ->register('setter_injection', AutowireSetter::class) |
| 72 | + ->setAutowired(true); |
| 73 | + |
| 74 | + (new ResolveClassPass())->process($container); |
| 75 | + (new AutowireRequiredMethodsPass())->process($container); |
| 76 | + |
| 77 | + $methodCalls = $container->getDefinition('setter_injection')->getMethodCalls(); |
| 78 | + $this->assertSame([['setFoo', []]], $methodCalls); |
| 79 | + } |
| 80 | + |
57 | 81 | public function testExplicitMethodInjection()
|
58 | 82 | {
|
59 | 83 | $container = new ContainerBuilder();
|
@@ -124,4 +148,26 @@ public function testWitherWithStaticReturnTypeInjection()
|
124 | 148 | ];
|
125 | 149 | $this->assertSame($expected, $methodCalls);
|
126 | 150 | }
|
| 151 | + |
| 152 | + /** |
| 153 | + * @requires PHP 8 |
| 154 | + */ |
| 155 | + public function testWitherInjectionWithAttribute() |
| 156 | + { |
| 157 | + if (!class_exists(Required::class)) { |
| 158 | + $this->markTestSkipped('symfony/service-contracts 2.2 required'); |
| 159 | + } |
| 160 | + |
| 161 | + $container = new ContainerBuilder(); |
| 162 | + $container->register(Foo::class); |
| 163 | + |
| 164 | + $container |
| 165 | + ->register('wither', AutowireWither::class) |
| 166 | + ->setAutowired(true); |
| 167 | + |
| 168 | + (new ResolveClassPass())->process($container); |
| 169 | + (new AutowireRequiredMethodsPass())->process($container); |
| 170 | + |
| 171 | + $this->assertSame([['withFoo', [], true]], $container->getDefinition('wither')->getMethodCalls()); |
| 172 | + } |
127 | 173 | }
|
0 commit comments