Skip to content

Commit

Permalink
Replace comment with real method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed May 25, 2024
1 parent cbfd23a commit 00d4b07
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 52 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: Added type declarations

The code base is now fully typed, meaning properties, parameters and return
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ parameters:
count: 1
path: src/Persistence/Mapping/Driver/StaticPHPDriver.php

-
message: "#^Call to function method_exists\\(\\) with TObjectManager of Doctrine\\\\Persistence\\\\ObjectManager and 'isUninitializedObje…' will always evaluate to true\\.$#"
count: 1
path: src/Persistence/ObjectManagerDecorator.php

-
message: "#^Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:__construct\\(\\) does not call parent constructor from ReflectionProperty\\.$#"
count: 1
Expand Down
9 changes: 4 additions & 5 deletions src/Persistence/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down Expand Up @@ -122,6 +118,9 @@ public function getMetadataFactory(): ClassMetadataFactory;
*/
public function initializeObject(object $obj): void;

/** 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.
*/
Expand Down
22 changes: 0 additions & 22 deletions src/Persistence/ObjectManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

namespace Doctrine\Persistence;

use BadMethodCallException;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;

use function get_class;
use function method_exists;
use function sprintf;

/**
* Base class to simplify ObjectManager decorators
*
Expand Down Expand Up @@ -83,23 +78,6 @@ public function initializeObject(object $obj): void

public function isUninitializedObject(mixed $value): bool
{
if (! method_exists($this->wrapped, 'isUninitializedObject')) {
$wrappedClass = get_class($this->wrapped);

throw new BadMethodCallException(sprintf(
<<<'EXCEPTION'
Context: Trying to call %s
Problem: The wrapped ObjectManager, an instance of %s does not implement this method.
Solution: Implement %s::isUninitializedObject() with a signature compatible with this one:
public function isUninitializedObject(mixed $value): bool
EXCEPTION
,
__METHOD__,
$wrappedClass,
$wrappedClass,
));
}

return $this->wrapped->isUninitializedObject($value);
}

Expand Down
22 changes: 2 additions & 20 deletions tests/Persistence/ObjectManagerDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\Persistence;

use BadMethodCallException;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\ObjectManager;
Expand Down Expand Up @@ -159,32 +158,15 @@ public function testIsUninitializedObject(): void
{
$object = new TestObject();

$wrapped = $this->createMock(ObjectManagerV4::class);
$decorated = new NullObjectManagerDecorator($wrapped);
$wrapped->expects(self::once())
$this->wrapped->expects(self::once())
->method('isUninitializedObject')
->with($object)
->willReturn(false);

self::assertFalse($decorated->isUninitializedObject($object));
}

public function testIsThrowsWhenTheWrappedObjectManagerDoesNotImplementObjectManagerV4(): void
{
$object = new TestObject();

$this->expectException(BadMethodCallException::class);
$decorated = new NullObjectManagerDecorator($this->createMock(ObjectManager::class));

self::assertFalse($decorated->isUninitializedObject($object));
self::assertFalse($this->decorated->isUninitializedObject($object));
}
}

interface ObjectManagerV4 extends ObjectManager
{
public function isUninitializedObject(mixed $object): bool;
}

/** @extends ObjectManagerDecorator<ObjectManager&MockObject> */
class NullObjectManagerDecorator extends ObjectManagerDecorator
{
Expand Down

0 comments on commit 00d4b07

Please sign in to comment.