diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0eeab36e..b041a5dc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Proxy\ProxyFactory; use InvalidArgumentException; use ReflectionClass; @@ -661,7 +662,14 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition ->arrayNode('schema_ignore_classes') ->prototype('scalar')->end() ->end() - ->scalarNode('report_fields_where_declared')->defaultFalse()->info('Set to "true" to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.16 and will be mandatory in ORM 3.0. See https://github.com/doctrine/orm/pull/10455.')->end() + ->booleanNode('report_fields_where_declared') + ->defaultValue(! class_exists(AnnotationDriver::class)) + ->info('Set to "true" to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.16 and will be mandatory in ORM 3.0. See https://github.com/doctrine/orm/pull/10455.') + ->validate() + ->ifTrue(static fn (bool $v): bool => ! class_exists(AnnotationDriver::class) && ! $v) + ->thenInvalid('The setting "report_fields_where_declared" cannot be disabled for ORM 3.') + ->end() + ->end() ->booleanNode('validate_xml_mapping')->defaultFalse()->info('Set to "true" to opt-in to the new mapping driver mode that was added in Doctrine ORM 2.14 and will be mandatory in ORM 3.0. See https://github.com/doctrine/orm/pull/6728.')->end() ->end() ->children() diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 677ccec6..fcb21d96 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -17,6 +17,7 @@ use Doctrine\ORM\Configuration as OrmConfiguration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver; use Doctrine\ORM\Proxy\ProxyFactory; use Generator; @@ -28,6 +29,7 @@ use Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -568,7 +570,7 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity', ], ), - false, + ! class_exists(AnnotationDriver::class), ]); $ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver'); @@ -627,7 +629,7 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void [ __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity', ], - false, + ! class_exists(AnnotationDriver::class), ]); } @@ -972,6 +974,21 @@ public function testDisablingLazyGhostOnOrm3Throws(): void $this->loadContainer('orm_no_lazy_ghost'); } + public function testDisablingReportFieldsWhereDeclaredOnOrm3Throws(): void + { + if (! interface_exists(EntityManagerInterface::class)) { + self::markTestSkipped('This test requires ORM'); + } + + if (class_exists(AnnotationDriver::class)) { + self::markTestSkipped('This test requires ORM 3.'); + } + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Invalid configuration for path "doctrine.orm.entity_managers.default.report_fields_where_declared": The setting "report_fields_where_declared" cannot be disabled for ORM 3.'); + $this->loadContainer('orm_no_report_fields'); + } + public function testResolveTargetEntity(): void { if (! interface_exists(EntityManagerInterface::class)) { diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_no_report_fields.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_no_report_fields.xml new file mode 100644 index 00000000..a87b30b0 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_no_report_fields.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_no_report_fields.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_no_report_fields.yml new file mode 100644 index 00000000..f8a42fd1 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_no_report_fields.yml @@ -0,0 +1,9 @@ +doctrine: + dbal: + default_connection: default + connections: + default: + dbname: db + + orm: + report_fields_where_declared: false