Skip to content

Commit 40cbf43

Browse files
authored
Merge pull request #371 from greg0ire/real-is-uninitialized
Replace comment with real method signature
2 parents cbfd23a + 00d4b07 commit 40cbf43

5 files changed

Lines changed: 11 additions & 52 deletions

File tree

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 4.0
1010

11+
## BC Break: Added `ObjectManager::isUninitializedObject()`
12+
13+
Classes implementing `Doctrine\Persistence\ObjectManager` must implement this
14+
new method.
15+
1116
## BC Break: Added type declarations
1217

1318
The code base is now fully typed, meaning properties, parameters and return

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ parameters:
55
count: 1
66
path: src/Persistence/Mapping/Driver/StaticPHPDriver.php
77

8-
-
9-
message: "#^Call to function method_exists\\(\\) with TObjectManager of Doctrine\\\\Persistence\\\\ObjectManager and 'isUninitializedObje…' will always evaluate to true\\.$#"
10-
count: 1
11-
path: src/Persistence/ObjectManagerDecorator.php
12-
138
-
149
message: "#^Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:__construct\\(\\) does not call parent constructor from ReflectionProperty\\.$#"
1510
count: 1

src/Persistence/ObjectManager.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
use Doctrine\Persistence\Mapping\ClassMetadata;
88
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
99

10-
/**
11-
* Contract for a Doctrine persistence layer ObjectManager class to implement.
12-
*
13-
* @method bool isUninitializedObject(mixed $value) Implementing this method will be mandatory in version 4.
14-
*/
10+
/** Contract for a Doctrine persistence layer ObjectManager class to implement. */
1511
interface ObjectManager
1612
{
1713
/**
@@ -122,6 +118,9 @@ public function getMetadataFactory(): ClassMetadataFactory;
122118
*/
123119
public function initializeObject(object $obj): void;
124120

121+
/** Helper method to check whether a lazy loading proxy or persistent collection has been initialized. */
122+
public function isUninitializedObject(mixed $value): bool;
123+
125124
/**
126125
* Checks if the object is part of the current UnitOfWork and therefore managed.
127126
*/

src/Persistence/ObjectManagerDecorator.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
namespace Doctrine\Persistence;
66

7-
use BadMethodCallException;
87
use Doctrine\Persistence\Mapping\ClassMetadata;
98
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
109

11-
use function get_class;
12-
use function method_exists;
13-
use function sprintf;
14-
1510
/**
1611
* Base class to simplify ObjectManager decorators
1712
*
@@ -83,23 +78,6 @@ public function initializeObject(object $obj): void
8378

8479
public function isUninitializedObject(mixed $value): bool
8580
{
86-
if (! method_exists($this->wrapped, 'isUninitializedObject')) {
87-
$wrappedClass = get_class($this->wrapped);
88-
89-
throw new BadMethodCallException(sprintf(
90-
<<<'EXCEPTION'
91-
Context: Trying to call %s
92-
Problem: The wrapped ObjectManager, an instance of %s does not implement this method.
93-
Solution: Implement %s::isUninitializedObject() with a signature compatible with this one:
94-
public function isUninitializedObject(mixed $value): bool
95-
EXCEPTION
96-
,
97-
__METHOD__,
98-
$wrappedClass,
99-
$wrappedClass,
100-
));
101-
}
102-
10381
return $this->wrapped->isUninitializedObject($value);
10482
}
10583

tests/Persistence/ObjectManagerDecoratorTest.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\Tests\Persistence;
66

7-
use BadMethodCallException;
87
use Doctrine\Persistence\Mapping\ClassMetadata;
98
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
109
use Doctrine\Persistence\ObjectManager;
@@ -159,32 +158,15 @@ public function testIsUninitializedObject(): void
159158
{
160159
$object = new TestObject();
161160

162-
$wrapped = $this->createMock(ObjectManagerV4::class);
163-
$decorated = new NullObjectManagerDecorator($wrapped);
164-
$wrapped->expects(self::once())
161+
$this->wrapped->expects(self::once())
165162
->method('isUninitializedObject')
166163
->with($object)
167164
->willReturn(false);
168165

169-
self::assertFalse($decorated->isUninitializedObject($object));
170-
}
171-
172-
public function testIsThrowsWhenTheWrappedObjectManagerDoesNotImplementObjectManagerV4(): void
173-
{
174-
$object = new TestObject();
175-
176-
$this->expectException(BadMethodCallException::class);
177-
$decorated = new NullObjectManagerDecorator($this->createMock(ObjectManager::class));
178-
179-
self::assertFalse($decorated->isUninitializedObject($object));
166+
self::assertFalse($this->decorated->isUninitializedObject($object));
180167
}
181168
}
182169

183-
interface ObjectManagerV4 extends ObjectManager
184-
{
185-
public function isUninitializedObject(mixed $object): bool;
186-
}
187-
188170
/** @extends ObjectManagerDecorator<ObjectManager&MockObject> */
189171
class NullObjectManagerDecorator extends ObjectManagerDecorator
190172
{

0 commit comments

Comments
 (0)