diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index c6dac14ec..588886fd7 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -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; @@ -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); diff --git a/Tests/Command/ImportMappingDoctrineCommandTest.php b/Tests/Command/ImportMappingDoctrineCommandTest.php index 99f693af4..bad76f0e5 100644 --- a/Tests/Command/ImportMappingDoctrineCommandTest.php +++ b/Tests/Command/ImportMappingDoctrineCommandTest.php @@ -4,6 +4,7 @@ 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; @@ -11,6 +12,7 @@ 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; @@ -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