Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/CreateDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Command/DropDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down