|
5 | 5 | namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler; |
6 | 6 |
|
7 | 7 | use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; |
| 8 | +use Doctrine\Bundle\DoctrineBundle\Tests\TestCase; |
8 | 9 | use Doctrine\ORM\EntityManagerInterface; |
9 | 10 | use Doctrine\ORM\Mapping\Driver\AttributeDriver; |
10 | 11 | use Doctrine\ORM\Mapping\Driver\XmlDriver; |
| 12 | +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; |
11 | 13 | use Doctrine\Persistence\Mapping\Driver\PHPDriver; |
12 | 14 | use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; |
13 | 15 | use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator; |
14 | | -use PHPUnit\Framework\TestCase; |
15 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
16 | 17 | use Symfony\Component\DependencyInjection\Definition; |
17 | 18 |
|
| 19 | +use function assert; |
18 | 20 | use function interface_exists; |
| 21 | +use function realpath; |
19 | 22 |
|
20 | 23 | class DoctrineOrmMappingsPassTest extends TestCase |
21 | 24 | { |
@@ -144,4 +147,38 @@ public function testCreateStaticPhpMappingDriver(): void |
144 | 147 | $args = $driverDef->getArguments(); |
145 | 148 | $this->assertSame($directories, $args[0]); |
146 | 149 | } |
| 150 | + |
| 151 | + public function testAttributeDriverIsRegistered(): void |
| 152 | + { |
| 153 | + if (! interface_exists(EntityManagerInterface::class)) { |
| 154 | + self::markTestSkipped('This test requires ORM'); |
| 155 | + } |
| 156 | + |
| 157 | + $driverNamespace = 'DoctrineBundle\Entity'; |
| 158 | + $container = $this->createXmlBundleTestContainer( |
| 159 | + static function (ContainerBuilder $containerBuilder) use ($driverNamespace): void { |
| 160 | + $containerBuilder->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver( |
| 161 | + [$driverNamespace], |
| 162 | + /** @phpstan-ignore argument.type */ |
| 163 | + [realpath(__DIR__ . '/Entity')], |
| 164 | + )); |
| 165 | + }, |
| 166 | + ); |
| 167 | + |
| 168 | + $metadataDriver = $container->get('doctrine.orm.default_metadata_driver'); |
| 169 | + /** |
| 170 | + * @phpstan-ignore function.impossibleType, instanceof.alwaysFalse ( |
| 171 | + * PHPStan analyzes against TestKernel container which includes |
| 172 | + * MappingDriver decorator, |
| 173 | + * but this test uses createXmlBundleTestContainer which doesn't run |
| 174 | + * IdGeneratorPass, so no decorator exists at runtime, and the type |
| 175 | + * of doctrine.orm.default_metadata_driver ends up being |
| 176 | + * Doctrine\Persistence\Mapping\Driver\MappingDriverChain, not |
| 177 | + * Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver) |
| 178 | + */ |
| 179 | + assert($metadataDriver instanceof MappingDriverChain); |
| 180 | + |
| 181 | + $driver = $metadataDriver->getDrivers()[$driverNamespace]; |
| 182 | + $this->assertTrue($driver instanceof AttributeDriver); |
| 183 | + } |
147 | 184 | } |
0 commit comments