Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Doctrine ORM 3 support #1450

Merged
merged 3 commits into from
Dec 25, 2021
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
16 changes: 16 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\ORM\UnitOfWork;
use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
Expand Down Expand Up @@ -460,6 +463,19 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->removeDefinition('doctrine.uuid_generator');
}

// not available in Doctrine ORM 3.0 and higher
if (! class_exists(ConvertMappingCommand::class)) {
$container->removeDefinition('doctrine.mapping_convert_command');
}

if (! class_exists(EnsureProductionSettingsCommand::class)) {
$container->removeDefinition('doctrine.ensure_production_settings_command');
}

if (! class_exists(ClassMetadataExporter::class)) {
$container->removeDefinition('doctrine.mapping_import_command');
}

$entityManagers = [];
foreach (array_keys($config['entity_managers']) as $name) {
$entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
Expand Down
6 changes: 4 additions & 2 deletions Tests/Command/ImportMappingDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use function class_exists;
use function file_get_contents;
use function interface_exists;
use function sys_get_temp_dir;
Expand All @@ -26,11 +28,11 @@ class ImportMappingDoctrineCommandTest extends TestCase

public static function setUpBeforeClass(): void
{
if (interface_exists(EntityManagerInterface::class)) {
if (interface_exists(EntityManagerInterface::class) && class_exists(ClassMetadataExporter::class)) {
return;
}

self::markTestSkipped('This test requires ORM');
self::markTestSkipped('This test requires ORM version 2');
}

protected function setup(): void
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^9.0",
"doctrine/orm": "^2.9",
"doctrine/orm": "^2.9 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.3 || ^10.0",
"psalm/plugin-phpunit": "^0.16.1",
Expand All @@ -59,7 +59,11 @@
"vimeo/psalm": "^4.7"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated change, it needs comment from you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a new behavior of Composer. This is added when running composer update.

"composer/package-versions-deprecated": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"conflict": {
"doctrine/orm": "<2.9",
Expand Down