diff --git a/composer.json b/composer.json index f1359bd65..7341bdcfc 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "psr/log": "^3.0", "symfony/doctrine-messenger": "^6.4 || ^7.0 || ^8.0", "symfony/expression-language": "^6.4 || ^7.0 || ^8.0", + "symfony/http-kernel": "^6.4 || ^7.0 || ^8.0", "symfony/messenger": "^6.4 || ^7.0 || ^8.0", "symfony/property-info": "^6.4 || ^7.0 || ^8.0", "symfony/security-bundle": "^6.4 || ^7.0 || ^8.0", diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b74499458..c55f89c0d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -284,7 +284,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void ->end() ->scalarNode('default_dbname') ->info( - 'Override the default database (postgres) to connect to for PostgreSQL connexion.', + 'Override the default database (postgres) to connect to for PostgreSQL connection.', ) ->end() ->scalarNode('sslmode') diff --git a/tests/Command/CreateDatabaseDoctrineTest.php b/tests/Command/CreateDatabaseDoctrineTest.php index 113ee347e..700d935e5 100644 --- a/tests/Command/CreateDatabaseDoctrineTest.php +++ b/tests/Command/CreateDatabaseDoctrineTest.php @@ -77,7 +77,7 @@ private function getMockContainer(string $connectionName, array|null $params = n $mockContainer = $this->createStub(Container::class); - $mockContainer->method('get')->with('doctrine')->willReturn($mockDoctrine); + $mockContainer->method('get')->willReturnMap([['doctrine', $mockDoctrine]]); return $mockContainer; } diff --git a/tests/Command/DropDatabaseDoctrineTest.php b/tests/Command/DropDatabaseDoctrineTest.php index 9311e2d8b..7206476f1 100644 --- a/tests/Command/DropDatabaseDoctrineTest.php +++ b/tests/Command/DropDatabaseDoctrineTest.php @@ -156,8 +156,7 @@ private function getMockContainer(string $connectionName, array $params): Stub $mockContainer = $this->createStub(Container::class); $mockContainer->method('get') - ->with('doctrine') - ->willReturn($mockDoctrine); + ->willReturnMap([['doctrine', $mockDoctrine]]); return $mockContainer; } diff --git a/tests/DependencyInjection/Compiler/DoctrineOrmMappingsPassTest.php b/tests/DependencyInjection/Compiler/DoctrineOrmMappingsPassTest.php index a5932966b..80a2d4550 100644 --- a/tests/DependencyInjection/Compiler/DoctrineOrmMappingsPassTest.php +++ b/tests/DependencyInjection/Compiler/DoctrineOrmMappingsPassTest.php @@ -5,16 +5,18 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; +use Doctrine\Bundle\DoctrineBundle\Tests\TestCase; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\Persistence\Mapping\Driver\PHPDriver; use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator; -use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use function assert; use function interface_exists; class DoctrineOrmMappingsPassTest extends TestCase @@ -144,4 +146,37 @@ public function testCreateStaticPhpMappingDriver(): void $args = $driverDef->getArguments(); $this->assertSame($directories, $args[0]); } + + public function testAttributeDriverIsRegistered(): void + { + if (! interface_exists(EntityManagerInterface::class)) { + self::markTestSkipped('This test requires ORM'); + } + + $driverNamespace = 'DoctrineBundle\Entity'; + $container = $this->createXmlBundleTestContainer( + static function (ContainerBuilder $containerBuilder) use ($driverNamespace): void { + $containerBuilder->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver( + [$driverNamespace], + ['dummy/path'], + )); + }, + ); + + $metadataDriver = $container->get('doctrine.orm.default_metadata_driver'); + /** + * @phpstan-ignore function.impossibleType, instanceof.alwaysFalse ( + * PHPStan analyzes against TestKernel container which includes + * MappingDriver decorator, + * but this test uses createXmlBundleTestContainer which doesn't run + * IdGeneratorPass, so no decorator exists at runtime, and the type + * of doctrine.orm.default_metadata_driver ends up being + * Doctrine\Persistence\Mapping\Driver\MappingDriverChain, not + * Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver) + */ + assert($metadataDriver instanceof MappingDriverChain); + + $driver = $metadataDriver->getDrivers()[$driverNamespace]; + $this->assertTrue($driver instanceof AttributeDriver); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index bea8df7dd..ec7967744 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,7 +19,7 @@ class TestCase extends BaseTestCase { - public function createXmlBundleTestContainer(): ContainerBuilder + public function createXmlBundleTestContainer(callable|null $func = null): ContainerBuilder { $container = new ContainerBuilder(new ParameterBag([ 'kernel.debug' => false, @@ -81,6 +81,11 @@ public function createXmlBundleTestContainer(): ContainerBuilder $compilerPassConfig->setRemovingPasses([]); // make all Doctrine services public, so we can fetch them in the test $compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass()); + + if ($func !== null) { + $func($container); + } + $container->compile(); return $container;