diff --git a/UPGRADE.md b/UPGRADE.md index 09100433fe0..6d40bf48078 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,10 @@ # Upgrade to 3.1 +## Deprecate passing null to `ClassMetadata::fullyQualifiedClassName()` + +Passing `null` to `Doctrine\ORM\ClassMetadata::fullyQualifiedClassName()` is +deprecated and will no longer be possible in 4.0. + ## Deprecate array access Using array access on instances of the following classes is deprecated: diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index 9d887be8325..e596537ca49 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -7,6 +7,7 @@ use BackedEnum; use BadMethodCallException; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Deprecations\Deprecation; use Doctrine\Instantiator\Instantiator; use Doctrine\Instantiator\InstantiatorInterface; use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation; @@ -2003,6 +2004,10 @@ protected function _storeAssociationMapping(AssociationMapping $assocMapping): v */ public function setCustomRepositoryClass(string|null $repositoryClassName): void { + if ($repositoryClassName === null) { + $this->customRepositoryClassName = null; + } + $this->customRepositoryClassName = $this->fullyQualifiedClassName($repositoryClassName); } @@ -2475,6 +2480,13 @@ public function getAssociationMappedByTargetField(string $assocName): string public function fullyQualifiedClassName(string|null $className): string|null { if ($className === null) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/11294', + 'Passing null to %s is deprecated and will not be supported in Doctrine ORM 4.0', + __METHOD__, + ); + return null; } diff --git a/tests/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Tests/ORM/Mapping/ClassMetadataTest.php index be44c416aea..acbedcc584c 100644 --- a/tests/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Tests/ORM/Mapping/ClassMetadataTest.php @@ -6,6 +6,7 @@ use ArrayObject; use Doctrine\DBAL\Types\Types; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ChainTypedFieldMapper; use Doctrine\ORM\Mapping\ClassMetadata; @@ -66,6 +67,8 @@ class ClassMetadataTest extends OrmTestCase { + use VerifyDeprecations; + public function testClassMetadataInstanceSerialization(): void { $cm = new ClassMetadata(CmsUser::class); @@ -1052,6 +1055,15 @@ public function testItAddingLifecycleCallbackOnEmbeddedClassIsIllegal(): void $metadata->addLifecycleCallback('foo', 'bar'); } + + public function testGettingAnFQCNForNullIsDeprecated(): void + { + $metadata = new ClassMetadata(self::class); + + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11294'); + + $metadata->fullyQualifiedClassName(null); + } } #[MappedSuperclass]