|
29 | 29 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent;
|
30 | 30 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo;
|
31 | 31 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\FooInterface;
|
| 32 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\NotFoo; |
32 | 33 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\AnotherSub;
|
33 | 34 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\AnotherSub\DeeperBaz;
|
34 | 35 | use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\OtherDir\Baz;
|
@@ -196,6 +197,7 @@ public function testNestedRegisterClasses()
|
196 | 197 | $this->assertTrue($container->has(Bar::class));
|
197 | 198 | $this->assertTrue($container->has(Baz::class));
|
198 | 199 | $this->assertTrue($container->has(Foo::class));
|
| 200 | + $this->assertTrue($container->has(NotFoo::class)); |
199 | 201 |
|
200 | 202 | $this->assertEquals([FooInterface::class], array_keys($container->getAliases()));
|
201 | 203 |
|
@@ -302,6 +304,47 @@ public function testRegisterClassesWithWhenEnv(?string $env, bool $expected)
|
302 | 304 | $this->assertSame($expected, $container->getDefinition(Foo::class)->hasTag('container.excluded'));
|
303 | 305 | }
|
304 | 306 |
|
| 307 | + /** |
| 308 | + * @dataProvider provideEnvAndExpectedExclusions |
| 309 | + */ |
| 310 | + public function testRegisterWithNotWhenAttributes(string $env, bool $expectedNotFooExclusion) |
| 311 | + { |
| 312 | + $container = new ContainerBuilder(); |
| 313 | + $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'), $env); |
| 314 | + |
| 315 | + $loader->registerClasses( |
| 316 | + (new Definition())->setAutoconfigured(true), |
| 317 | + 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', |
| 318 | + 'Prototype/*', |
| 319 | + 'Prototype/BadAttributes/*' |
| 320 | + ); |
| 321 | + |
| 322 | + $this->assertTrue($container->has(NotFoo::class)); |
| 323 | + $this->assertSame($expectedNotFooExclusion, $container->getDefinition(NotFoo::class)->hasTag('container.excluded')); |
| 324 | + } |
| 325 | + |
| 326 | + public static function provideEnvAndExpectedExclusions(): iterable |
| 327 | + { |
| 328 | + yield ['dev', true]; |
| 329 | + yield ['prod', true]; |
| 330 | + yield ['test', false]; |
| 331 | + } |
| 332 | + |
| 333 | + public function testRegisterThrowsWithBothWhenAndNotWhenAttribute() |
| 334 | + { |
| 335 | + $container = new ContainerBuilder(); |
| 336 | + $loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'), 'dev'); |
| 337 | + |
| 338 | + $this->expectException(LogicException::class); |
| 339 | + $this->expectExceptionMessage('The "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadAttributes\WhenNotWhenFoo" class cannot have both #[When] and #[WhenNot] attributes.'); |
| 340 | + |
| 341 | + $loader->registerClasses( |
| 342 | + (new Definition())->setAutoconfigured(true), |
| 343 | + 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadAttributes\\', |
| 344 | + 'Prototype/BadAttributes/*', |
| 345 | + ); |
| 346 | + } |
| 347 | + |
305 | 348 | /**
|
306 | 349 | * @dataProvider provideResourcesWithAsAliasAttributes
|
307 | 350 | */
|
|
0 commit comments