|
4 | 4 |
|
5 | 5 | namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection; |
6 | 6 |
|
| 7 | +use Closure; |
7 | 8 | use Composer\InstalledVersions; |
8 | 9 | use Composer\Semver\VersionParser; |
9 | 10 | use Doctrine\Bundle\MongoDBBundle\Attribute\MapDocument; |
10 | 11 | use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; |
11 | 12 | use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\DocumentListenerBundle\EventListener\TestAttributeListener; |
| 13 | +use Doctrine\ODM\MongoDB\Mapping\Annotations; |
12 | 14 | use PHPUnit\Framework\TestCase; |
13 | 15 | use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; |
14 | 16 | use Symfony\Component\DependencyInjection\Alias; |
| 17 | +use Symfony\Component\DependencyInjection\ChildDefinition; |
15 | 18 | use Symfony\Component\DependencyInjection\Container; |
16 | 19 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | 20 | use Symfony\Component\DependencyInjection\Definition; |
|
23 | 26 | use function class_exists; |
24 | 27 | use function interface_exists; |
25 | 28 | use function is_dir; |
| 29 | +use function sprintf; |
26 | 30 | use function sys_get_temp_dir; |
27 | 31 |
|
28 | 32 | class DoctrineMongoDBExtensionTest extends TestCase |
@@ -102,6 +106,36 @@ public function testAsDocumentListenerAttribute(): void |
102 | 106 | ], $listenerDefinition->getTag('doctrine_mongodb.odm.event_listener')); |
103 | 107 | } |
104 | 108 |
|
| 109 | + /** @return array<array{0: class-string}> */ |
| 110 | + public static function provideAttributeExcludedFromContainer(): array |
| 111 | + { |
| 112 | + return [ |
| 113 | + 'Document' => [Annotations\Document::class], |
| 114 | + 'EmbeddedDocument' => [Annotations\EmbeddedDocument::class], |
| 115 | + 'MappedSuperclass' => [Annotations\MappedSuperclass::class], |
| 116 | + 'View' => [Annotations\View::class], |
| 117 | + 'QueryResultDocument' => [Annotations\QueryResultDocument::class], |
| 118 | + 'File' => [Annotations\File::class], |
| 119 | + ]; |
| 120 | + } |
| 121 | + |
| 122 | + /** @dataProvider provideAttributeExcludedFromContainer */ |
| 123 | + public function testDocumentAttributeExcludesFromContainer(string $class): void |
| 124 | + { |
| 125 | + $container = $this->getContainer(); |
| 126 | + $extension = new DoctrineMongoDBExtension(); |
| 127 | + $extension->load($this->buildConfiguration(), $container); |
| 128 | + |
| 129 | + $attributes = $container->getAutoconfiguredAttributes(); |
| 130 | + $this->assertInstanceOf(Closure::class, $attributes[$class]); |
| 131 | + |
| 132 | + $definition = new ChildDefinition(''); |
| 133 | + $attributes[$class]($definition); |
| 134 | + |
| 135 | + $this->assertSame([['source' => sprintf('with #[%s] attribute', $class)]], $definition->getTag('container.excluded')); |
| 136 | + $this->assertTrue($definition->isAbstract()); |
| 137 | + } |
| 138 | + |
105 | 139 | /** @param string|string[] $bundles */ |
106 | 140 | private function getContainer(string|array $bundles = 'OtherXmlBundle'): ContainerBuilder |
107 | 141 | { |
|
0 commit comments