Skip to content

Commit 4089f14

Browse files
authored
Enable report_fields_where_declared for ORM 3 (#1729)
1 parent 8c42712 commit 4089f14

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

DependencyInjection/Configuration.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\ORM\EntityManager;
77
use Doctrine\ORM\EntityRepository;
88
use Doctrine\ORM\Mapping\ClassMetadataFactory;
9+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
910
use Doctrine\ORM\Proxy\ProxyFactory;
1011
use InvalidArgumentException;
1112
use ReflectionClass;
@@ -661,7 +662,14 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
661662
->arrayNode('schema_ignore_classes')
662663
->prototype('scalar')->end()
663664
->end()
664-
->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()
665+
->booleanNode('report_fields_where_declared')
666+
->defaultValue(! class_exists(AnnotationDriver::class))
667+
->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.')
668+
->validate()
669+
->ifTrue(static fn (bool $v): bool => ! class_exists(AnnotationDriver::class) && ! $v)
670+
->thenInvalid('The setting "report_fields_where_declared" cannot be disabled for ORM 3.')
671+
->end()
672+
->end()
665673
->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()
666674
->end()
667675
->children()

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ORM\Configuration as OrmConfiguration;
1818
use Doctrine\ORM\EntityManager;
1919
use Doctrine\ORM\EntityManagerInterface;
20+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
2021
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
2122
use Doctrine\ORM\Proxy\ProxyFactory;
2223
use Generator;
@@ -28,6 +29,7 @@
2829
use Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator;
2930
use Symfony\Component\Cache\Adapter\ArrayAdapter;
3031
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
32+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
3133
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
3234
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
3335
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -568,7 +570,7 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void
568570
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity',
569571
],
570572
),
571-
false,
573+
! class_exists(AnnotationDriver::class),
572574
]);
573575

574576
$ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver');
@@ -627,7 +629,7 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void
627629
[
628630
__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity',
629631
],
630-
false,
632+
! class_exists(AnnotationDriver::class),
631633
]);
632634
}
633635

@@ -972,6 +974,21 @@ public function testDisablingLazyGhostOnOrm3Throws(): void
972974
$this->loadContainer('orm_no_lazy_ghost');
973975
}
974976

977+
public function testDisablingReportFieldsWhereDeclaredOnOrm3Throws(): void
978+
{
979+
if (! interface_exists(EntityManagerInterface::class)) {
980+
self::markTestSkipped('This test requires ORM');
981+
}
982+
983+
if (class_exists(AnnotationDriver::class)) {
984+
self::markTestSkipped('This test requires ORM 3.');
985+
}
986+
987+
$this->expectException(InvalidConfigurationException::class);
988+
$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.');
989+
$this->loadContainer('orm_no_report_fields');
990+
}
991+
975992
public function testResolveTargetEntity(): void
976993
{
977994
if (! interface_exists(EntityManagerInterface::class)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:srv="http://symfony.com/schema/dic/services"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
8+
9+
<config>
10+
<dbal default-connection="default">
11+
<connection name="default" dbname="db" />
12+
</dbal>
13+
14+
<orm report-fields-where-declared="false" />
15+
</config>
16+
</srv:container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
doctrine:
2+
dbal:
3+
default_connection: default
4+
connections:
5+
default:
6+
dbname: db
7+
8+
orm:
9+
report_fields_where_declared: false

0 commit comments

Comments
 (0)