Skip to content

Commit 9a2b3d4

Browse files
committed
Merge remote-tracking branch 'origin/2.18.x' into 3.2.x
2 parents 1d5c4f3 + a458f66 commit 9a2b3d4

6 files changed

Lines changed: 48 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"psr/log": "^3.0",
5454
"symfony/doctrine-messenger": "^6.4 || ^7.0 || ^8.0",
5555
"symfony/expression-language": "^6.4 || ^7.0 || ^8.0",
56+
"symfony/http-kernel": "^6.4 || ^7.0 || ^8.0",
5657
"symfony/messenger": "^6.4 || ^7.0 || ^8.0",
5758
"symfony/property-info": "^6.4 || ^7.0 || ^8.0",
5859
"symfony/security-bundle": "^6.4 || ^7.0 || ^8.0",

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
284284
->end()
285285
->scalarNode('default_dbname')
286286
->info(
287-
'Override the default database (postgres) to connect to for PostgreSQL connexion.',
287+
'Override the default database (postgres) to connect to for PostgreSQL connection.',
288288
)
289289
->end()
290290
->scalarNode('sslmode')

tests/Command/CreateDatabaseDoctrineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function getMockContainer(string $connectionName, array|null $params = n
7777

7878
$mockContainer = $this->createStub(Container::class);
7979

80-
$mockContainer->method('get')->with('doctrine')->willReturn($mockDoctrine);
80+
$mockContainer->method('get')->willReturnMap([['doctrine', $mockDoctrine]]);
8181

8282
return $mockContainer;
8383
}

tests/Command/DropDatabaseDoctrineTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ private function getMockContainer(string $connectionName, array $params): Stub
156156
$mockContainer = $this->createStub(Container::class);
157157

158158
$mockContainer->method('get')
159-
->with('doctrine')
160-
->willReturn($mockDoctrine);
159+
->willReturnMap([['doctrine', $mockDoctrine]]);
161160

162161
return $mockContainer;
163162
}

tests/DependencyInjection/Compiler/DoctrineOrmMappingsPassTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler;
66

77
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
8+
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
89
use Doctrine\ORM\EntityManagerInterface;
910
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
1011
use Doctrine\ORM\Mapping\Driver\XmlDriver;
12+
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
1113
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
1214
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
1315
use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
14-
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
1718

19+
use function assert;
1820
use function interface_exists;
21+
use function realpath;
1922

2023
class DoctrineOrmMappingsPassTest extends TestCase
2124
{
@@ -144,4 +147,38 @@ public function testCreateStaticPhpMappingDriver(): void
144147
$args = $driverDef->getArguments();
145148
$this->assertSame($directories, $args[0]);
146149
}
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+
}
147184
}

tests/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class TestCase extends BaseTestCase
2121
{
22-
public function createXmlBundleTestContainer(): ContainerBuilder
22+
public function createXmlBundleTestContainer(callable|null $func = null): ContainerBuilder
2323
{
2424
$container = new ContainerBuilder(new ParameterBag([
2525
'kernel.debug' => false,
@@ -81,6 +81,11 @@ public function createXmlBundleTestContainer(): ContainerBuilder
8181
$compilerPassConfig->setRemovingPasses([]);
8282
// make all Doctrine services public, so we can fetch them in the test
8383
$compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass());
84+
85+
if ($func !== null) {
86+
$func($container);
87+
}
88+
8489
$container->compile();
8590

8691
return $container;

0 commit comments

Comments
 (0)