Skip to content

Commit

Permalink
fix: don't register doctrine:mapping:import when using ORM v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas authored and ostrolucky committed Dec 25, 2021
1 parent 15af5b5 commit 6ac3cc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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 @@ -471,6 +472,10 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$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

0 comments on commit 6ac3cc6

Please sign in to comment.