From 4ca86dfa756c3c6afe7aae85a1206c762f6c55a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 May 2024 21:30:50 +0200 Subject: [PATCH] Replace comment with real method signature --- UPGRADE.md | 5 +++++ src/Persistence/ObjectManager.php | 9 ++++----- src/Persistence/ObjectManagerDecorator.php | 5 +++++ tests/Persistence/ObjectManagerDecoratorTest.php | 13 +++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 533106db..b072d3ed 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,11 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC Break: Added `ObjectManager::isUninitializedObject()` + +Classes implementing `Doctrine\Persistence\ObjectManager` must implement this +new method. + ## BC Break: Dropped support for Common proxies Proxy objects implementing the `Doctrine\Common\Proxy\Proxy` interface are not diff --git a/src/Persistence/ObjectManager.php b/src/Persistence/ObjectManager.php index efac5c31..50d1c4bd 100644 --- a/src/Persistence/ObjectManager.php +++ b/src/Persistence/ObjectManager.php @@ -7,11 +7,7 @@ use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\ClassMetadataFactory; -/** - * Contract for a Doctrine persistence layer ObjectManager class to implement. - * - * @method bool isUninitializedObject(mixed $value) Implementing this method will be mandatory in version 4. - */ +/** Contract for a Doctrine persistence layer ObjectManager class to implement. */ interface ObjectManager { /** @@ -136,6 +132,9 @@ public function getMetadataFactory(); */ public function initializeObject(object $obj); + /** Helper method to check whether a lazy loading proxy or persistent collection has been initialized. */ + public function isUninitializedObject(mixed $value): bool; + /** * Checks if the object is part of the current UnitOfWork and therefore managed. * diff --git a/src/Persistence/ObjectManagerDecorator.php b/src/Persistence/ObjectManagerDecorator.php index 8c038b8e..fcb06d5b 100644 --- a/src/Persistence/ObjectManagerDecorator.php +++ b/src/Persistence/ObjectManagerDecorator.php @@ -82,6 +82,11 @@ public function initializeObject(object $obj) $this->wrapped->initializeObject($obj); } + public function isUninitializedObject(mixed $value): bool + { + return $this->wrapped->isUninitializedObject($value); + } + /** * {@inheritDoc} */ diff --git a/tests/Persistence/ObjectManagerDecoratorTest.php b/tests/Persistence/ObjectManagerDecoratorTest.php index b2ccb1d2..978d62a0 100644 --- a/tests/Persistence/ObjectManagerDecoratorTest.php +++ b/tests/Persistence/ObjectManagerDecoratorTest.php @@ -155,6 +155,19 @@ public function testContains(): void self::assertTrue($this->decorated->contains($object)); } + + /** @requires PHP 8.0 */ + public function testIsUninitializedObject(): void + { + $object = new TestObject(); + + $this->wrapped->expects(self::once()) + ->method('isUninitializedObject') + ->with($object) + ->willReturn(false); + + self::assertFalse($this->decorated->isUninitializedObject($object)); + } } /** @extends ObjectManagerDecorator */