diff --git a/docs/en/reference/unitofwork.rst b/docs/en/reference/unitofwork.rst
index 49530c82db5..1198af6bc7e 100644
--- a/docs/en/reference/unitofwork.rst
+++ b/docs/en/reference/unitofwork.rst
@@ -37,8 +37,8 @@ will still end up with the same reference:
public function testIdentityMapReference(): void
{
$objectA = $this->entityManager->getReference('EntityName', 1);
- // check for proxyinterface
- $this->assertInstanceOf('Doctrine\Persistence\Proxy', $objectA);
+ // check entity is not initialized
+ $this->assertTrue($this->entityManager->isUninitializedObject($objectA));
$objectB = $this->entityManager->find('EntityName', 1);
diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php
index d1d351e1e77..08e703cd4b0 100644
--- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php
+++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php
@@ -18,7 +18,6 @@
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\UnitOfWork;
-use Doctrine\Persistence\Proxy;
use function array_map;
use function array_shift;
@@ -311,7 +310,7 @@ private function storeAssociationCache(QueryCacheKey $key, AssociationMapping $a
$assocIdentifier = $this->uow->getEntityIdentifier($assocValue);
$entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier);
- if (! $assocValue instanceof Proxy && ($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey)) {
+ if (! $this->uow->isUninitializedObject($assocValue) && ($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey)) {
// Entity put fail
if (! $assocPersister->storeEntityCache($assocValue, $entityKey)) {
return null;
diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php
index fdabf133b5d..7af9cc9ad88 100644
--- a/lib/Doctrine/ORM/EntityManager.php
+++ b/lib/Doctrine/ORM/EntityManager.php
@@ -583,6 +583,14 @@ public function initializeObject(object $obj): void
$this->unitOfWork->initializeObject($obj);
}
+ /**
+ * {@inheritDoc}
+ */
+ public function isUninitializedObject($obj): bool
+ {
+ return $this->unitOfWork->isUninitializedObject($obj);
+ }
+
public function getFilters(): FilterCollection
{
return $this->filterCollection ??= new FilterCollection($this);
diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
index af805a8cc7f..774100b6e5f 100644
--- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
@@ -10,7 +10,6 @@
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
-use Doctrine\Persistence\Proxy;
use function array_fill_keys;
use function array_keys;
@@ -430,7 +429,7 @@ protected function hydrateRowData(array $row, array &$result): void
// PATH B: Single-valued association
$reflFieldValue = $reflField->getValue($parentObject);
- if (! $reflFieldValue || isset($this->hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized())) {
+ if (! $reflFieldValue || isset($this->hints[Query::HINT_REFRESH]) || $this->uow->isUninitializedObject($reflFieldValue)) {
// we only need to take action if this value is null,
// we refresh the entity or its an uninitialized proxy.
if (isset($nonemptyComponents[$dqlAlias])) {
diff --git a/lib/Doctrine/ORM/Proxy/InternalProxy.php b/lib/Doctrine/ORM/Proxy/InternalProxy.php
new file mode 100644
index 00000000000..baa5703f2a3
--- /dev/null
+++ b/lib/Doctrine/ORM/Proxy/InternalProxy.php
@@ -0,0 +1,19 @@
+
+ *
+ * @method void __setInitialized(bool $initialized)
+ */
+interface InternalProxy extends Proxy
+{
+}
diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php
index 6f1f6e85e5d..dc7eaa0e576 100644
--- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php
+++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php
@@ -16,7 +16,6 @@
use Doctrine\ORM\UnitOfWork;
use Doctrine\ORM\Utility\IdentifierFlattener;
use Doctrine\Persistence\Mapping\ClassMetadata;
-use Doctrine\Persistence\Proxy;
use ReflectionProperty;
use Symfony\Component\VarExporter\ProxyHelper;
use Symfony\Component\VarExporter\VarExporter;
@@ -94,13 +93,13 @@ public function __construct(
$proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs);
if ($em->getConfiguration()->isLazyGhostObjectEnabled()) {
- $proxyGenerator->setPlaceholder('baseProxyInterface', Proxy::class);
+ $proxyGenerator->setPlaceholder('baseProxyInterface', InternalProxy::class);
$proxyGenerator->setPlaceholder('useLazyGhostTrait', $this->generateUseLazyGhostTrait(...));
$proxyGenerator->setPlaceholder('skippedProperties', $this->generateSkippedProperties(...));
$proxyGenerator->setPlaceholder('serializeImpl', $this->generateSerializeImpl(...));
$proxyGenerator->setProxyClassTemplate(self::PROXY_CLASS_TEMPLATE);
} else {
- $proxyGenerator->setPlaceholder('baseProxyInterface', CommonProxy::class);
+ $proxyGenerator->setPlaceholder('baseProxyInterface', CommonProxy::class . ', \\' . InternalProxy::class);
}
parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate);
@@ -122,7 +121,7 @@ public function getProxy($className, array $identifier)
$initializer = $this->definitions[$className]->initializer;
- $proxy->__construct(static function (Proxy $object) use ($initializer, $proxy): void {
+ $proxy->__construct(static function (InternalProxy $object) use ($initializer, $proxy): void {
$initializer($object, $proxy);
});
@@ -226,13 +225,13 @@ private function createInitializer(ClassMetadata $classMetadata, EntityPersister
/**
* Creates a closure capable of initializing a proxy
*
- * @return Closure(Proxy, Proxy):void
+ * @return Closure(InternalProxy, InternalProxy):void
*
* @throws EntityNotFoundException
*/
private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersister $entityPersister): Closure
{
- return function (Proxy $proxy, Proxy $original) use ($entityPersister, $classMetadata): void {
+ return function (InternalProxy $proxy, InternalProxy $original) use ($entityPersister, $classMetadata): void {
$identifier = $classMetadata->getIdentifierValues($original);
$entity = $entityPersister->loadById($identifier, $original);
diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
index 8219620ef19..71059f7d271 100644
--- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
+++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
@@ -8,7 +8,6 @@
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\UnitOfWork;
-use Doctrine\Persistence\Proxy;
use ReflectionObject;
use function count;
@@ -74,7 +73,7 @@ public function dumpIdentityMap(EntityManagerInterface $em): void
if ($value === null) {
fwrite($fh, " NULL\n");
} else {
- if ($value instanceof Proxy && ! $value->__isInitialized()) {
+ if ($uow->isUninitializedObject($value)) {
fwrite($fh, '[PROXY] ');
}
diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 579e85cdc26..8a2a839ed71 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
+++ b/lib/Doctrine/ORM/UnitOfWork.php
@@ -40,9 +40,9 @@
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister;
use Doctrine\ORM\Persisters\Entity\SingleTablePersister;
+use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\ORM\Utility\IdentifierFlattener;
use Doctrine\Persistence\PropertyChangedListener;
-use Doctrine\Persistence\Proxy;
use Exception;
use InvalidArgumentException;
use RuntimeException;
@@ -781,7 +781,7 @@ public function computeChangeSets(): void
foreach ($entitiesToProcess as $entity) {
// Ignore uninitialized proxy objects
- if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
+ if ($this->isUninitializedObject($entity)) {
continue;
}
@@ -805,7 +805,7 @@ public function computeChangeSets(): void
*/
private function computeAssociationChanges(AssociationMapping $assoc, mixed $value): void
{
- if ($value instanceof Proxy && ! $value->__isInitialized()) {
+ if ($this->isUninitializedObject($value)) {
return;
}
@@ -2015,7 +2015,7 @@ private function cascadeDetach(object $entity, array &$visited): void
*/
private function cascadePersist(object $entity, array &$visited): void
{
- if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
+ if ($this->isUninitializedObject($entity)) {
// nothing to do - proxy is not initialized, therefore we don't do anything with it
return;
}
@@ -2084,13 +2084,13 @@ private function cascadeRemove(object $entity, array &$visited): void
static fn (AssociationMapping $assoc): bool => $assoc->isCascadeRemove()
);
+ if ($associationMappings) {
+ $this->initializeObject($entity);
+ }
+
$entitiesToCascade = [];
foreach ($associationMappings as $assoc) {
- if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
- $entity->__load();
- }
-
$relatedEntities = $class->reflFields[$assoc->fieldName]->getValue($entity);
switch (true) {
@@ -2144,9 +2144,7 @@ public function lock(object $entity, LockMode|int $lockMode, DateTimeInterface|i
return;
}
- if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
- $entity->__load();
- }
+ $this->initializeObject($entity);
assert($class->versionField !== null);
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
@@ -2293,7 +2291,6 @@ public function createEntity(string $className, array $data, array &$hints = [])
$unmanagedProxy = $hints[Query::HINT_REFRESH_ENTITY];
if (
$unmanagedProxy !== $entity
- && $unmanagedProxy instanceof Proxy
&& $this->isIdentifierEquals($unmanagedProxy, $entity)
) {
// We will hydrate the given un-managed proxy anyway:
@@ -2302,7 +2299,7 @@ public function createEntity(string $className, array $data, array &$hints = [])
}
}
- if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
+ if ($this->isUninitializedObject($entity)) {
$entity->__setInitialized(true);
} else {
if (
@@ -2440,8 +2437,7 @@ public function createEntity(string $className, array $data, array &$hints = [])
$hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER &&
isset($hints[self::HINT_DEFEREAGERLOAD]) &&
! $targetClass->isIdentifierComposite &&
- $newValue instanceof Proxy &&
- $newValue->__isInitialized() === false
+ $this->isUninitializedObject($newValue)
) {
$this->eagerLoadingEntities[$targetClass->rootEntityName][$relatedIdHash] = current($associatedId);
}
@@ -2868,7 +2864,7 @@ public function getScheduledCollectionUpdates(): array
*/
public function initializeObject(object $obj): void
{
- if ($obj instanceof Proxy) {
+ if ($obj instanceof InternalProxy) {
$obj->__load();
return;
@@ -2879,6 +2875,18 @@ public function initializeObject(object $obj): void
}
}
+ /**
+ * Tests if a value is an uninitialized entity.
+ *
+ * @param mixed $obj
+ *
+ * @psalm-assert-if-true InternalProxy $obj
+ */
+ public function isUninitializedObject($obj): bool
+ {
+ return $obj instanceof InternalProxy && ! $obj->__isInitialized();
+ }
+
/**
* Helper method to show an object as string.
*/
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 98fb8b43d2d..736ecfddf7f 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -751,7 +751,7 @@
$classMetadata
- __construct(static function (Proxy $object) use ($initializer, $proxy): void {
+ __construct(static function (InternalProxy $object) use ($initializer, $proxy): void {
$initializer($object, $proxy);
})]]>
diff --git a/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php b/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php
index 12f99f0a6c2..68f987254c2 100644
--- a/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php
+++ b/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php
@@ -4,9 +4,9 @@
namespace Doctrine\Performance\LazyLoading;
+use Doctrine\ORM\Proxy\InternalProxy as Proxy;
use Doctrine\Performance\EntityManagerFactory;
use Doctrine\Performance\Mock\NonProxyLoadingEntityManager;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\CMS\CmsEmployee;
use Doctrine\Tests\Models\CMS\CmsUser;
diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
index f5159512f87..e0492f5d408 100644
--- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
@@ -8,9 +8,9 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\ORM\PersistentCollection;
+use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\IterableTester;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsArticle;
@@ -145,7 +145,7 @@ public function testBasicOneToOne(): void
// Address has been eager-loaded because it cant be lazy
self::assertInstanceOf(CmsAddress::class, $user2->address);
- self::assertNotInstanceOf(Proxy::class, $user2->address);
+ self::assertFalse($this->isUninitializedObject($user2->address));
}
#[Group('DDC-1230')]
@@ -547,8 +547,7 @@ public function testSetToOneAssociationWithGetReference(): void
// Assume we only got the identifier of the user and now want to attach
// the article to the user without actually loading it, using getReference().
$userRef = $this->_em->getReference(CmsUser::class, $user->getId());
- self::assertInstanceOf(Proxy::class, $userRef);
- self::assertFalse($userRef->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($userRef));
$article = new CmsArticle();
$article->topic = 'topic';
@@ -583,8 +582,7 @@ public function testAddToToManyAssociationWithGetReference(): void
// Assume we only got the identifier of the user and now want to attach
// the article to the user without actually loading it, using getReference().
$groupRef = $this->_em->getReference(CmsGroup::class, $group->id);
- self::assertInstanceOf(Proxy::class, $groupRef);
- self::assertFalse($groupRef->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($groupRef));
$user = new CmsUser();
$user->name = 'Guilherme';
@@ -762,9 +760,8 @@ public function testQueryEntityByReference(): void
->setParameter('user', $userRef)
->getSingleResult();
- self::assertInstanceOf(Proxy::class, $address2->getUser());
self::assertTrue($userRef === $address2->getUser());
- self::assertFalse($userRef->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($userRef));
self::assertEquals('Germany', $address2->country);
self::assertEquals('Berlin', $address2->city);
self::assertEquals('12345', $address2->zip);
@@ -966,8 +963,8 @@ public function testManyToOneFetchModeQuery(): void
->setParameter(1, $article->id)
->setFetchMode(CmsArticle::class, 'user', ClassMetadata::FETCH_EAGER)
->getSingleResult();
- self::assertInstanceOf(Proxy::class, $article->user, 'It IS a proxy, ...');
- self::assertTrue($article->user->__isInitialized(), '...but its initialized!');
+ self::assertInstanceOf(InternalProxy::class, $article->user, 'It IS a proxy, ...');
+ self::assertFalse($this->isUninitializedObject($article->user), '...but its initialized!');
$this->assertQueryCount(2);
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php
index 5edbfa71322..94f817a2353 100644
--- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php
@@ -7,7 +7,6 @@
use DateTime;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\PersistentCollection;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\IterableTester;
use Doctrine\Tests\Models\Company\CompanyAuction;
use Doctrine\Tests\Models\Company\CompanyEmployee;
@@ -301,7 +300,7 @@ public function testLazyLoading2(): void
$mainEvent = $result[0]->getMainEvent();
// mainEvent should have been loaded because it can't be lazy
self::assertInstanceOf(CompanyAuction::class, $mainEvent);
- self::assertNotInstanceOf(Proxy::class, $mainEvent);
+ self::assertFalse($this->isUninitializedObject($mainEvent));
$this->_em->clear();
@@ -432,13 +431,13 @@ public function testGetReferenceEntityWithSubclasses(): void
$this->_em->clear();
$ref = $this->_em->getReference(CompanyPerson::class, $manager->getId());
- self::assertNotInstanceOf(Proxy::class, $ref, 'Cannot Request a proxy from a class that has subclasses.');
+ self::assertFalse($this->isUninitializedObject($ref), 'Cannot Request a proxy from a class that has subclasses.');
self::assertInstanceOf(CompanyPerson::class, $ref);
self::assertInstanceOf(CompanyEmployee::class, $ref, 'Direct fetch of the reference has to load the child class Employee directly.');
$this->_em->clear();
$ref = $this->_em->getReference(CompanyManager::class, $manager->getId());
- self::assertInstanceOf(Proxy::class, $ref, 'A proxy can be generated only if no subclasses exists for the requested reference.');
+ self::assertTrue($this->isUninitializedObject($ref), 'A proxy can be generated only if no subclasses exists for the requested reference.');
}
#[Group('DDC-992')]
diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php
index 0ff79e9c7e0..9b9469ffa62 100644
--- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php
@@ -42,7 +42,7 @@ public function testSimpleDetachMerge(): void
$user2 = $this->_em->getReference($user::class, $userId);
$this->_em->flush();
- self::assertFalse($user2->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($user2));
$a = new DefaultValueAddress();
$a->country = 'de';
@@ -54,7 +54,7 @@ public function testSimpleDetachMerge(): void
$this->_em->persist($a);
$this->_em->flush();
- self::assertFalse($user2->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($user2));
$this->_em->clear();
$a2 = $this->_em->find($a::class, $a->id);
diff --git a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php
index c402508cdd9..ab5d0cbb7ff 100644
--- a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php
@@ -4,7 +4,6 @@
namespace Doctrine\Tests\ORM\Functional;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\DirectoryTree\Directory;
use Doctrine\Tests\Models\DirectoryTree\File;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -44,7 +43,7 @@ public function testCRUD(): void
$cleanFile = $this->_em->find($file::class, $file->getId());
self::assertInstanceOf(Directory::class, $cleanFile->getParent());
- self::assertInstanceOf(Proxy::class, $cleanFile->getParent());
+ self::assertTrue($this->isUninitializedObject($cleanFile->getParent()));
self::assertEquals($directory->getId(), $cleanFile->getParent()->getId());
self::assertInstanceOf(Directory::class, $cleanFile->getParent()->getParent());
self::assertEquals($root->getId(), $cleanFile->getParent()->getParent()->getId());
diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php
index a36c0fa4f58..ebd23a43635 100644
--- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php
@@ -6,7 +6,6 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -88,12 +87,12 @@ public function testEagerLoadsOneToManyAssociation(): void
$features = $product->getFeatures();
self::assertInstanceOf(ECommerceFeature::class, $features[0]);
- self::assertNotInstanceOf(Proxy::class, $features[0]->getProduct());
+ self::assertFalse($this->isUninitializedObject($features[0]->getProduct()));
self::assertSame($product, $features[0]->getProduct());
self::assertEquals('Model writing tutorial', $features[0]->getDescription());
self::assertInstanceOf(ECommerceFeature::class, $features[1]);
self::assertSame($product, $features[1]->getProduct());
- self::assertNotInstanceOf(Proxy::class, $features[1]->getProduct());
+ self::assertFalse($this->isUninitializedObject($features[1]->getProduct()));
self::assertEquals('Attributes examples', $features[1]->getDescription());
}
@@ -124,11 +123,10 @@ public function testLazyLoadsObjectsOnTheInverseSide(): void
$features = $query->getResult();
$product = $features[0]->getProduct();
- self::assertInstanceOf(Proxy::class, $product);
self::assertInstanceOf(ECommerceProduct::class, $product);
- self::assertFalse($product->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($product));
self::assertSame('Doctrine Cookbook', $product->getName());
- self::assertTrue($product->__isInitialized());
+ self::assertFalse($this->isUninitializedObject($product));
}
public function testLazyLoadsObjectsOnTheInverseSide2(): void
@@ -139,7 +137,7 @@ public function testLazyLoadsObjectsOnTheInverseSide2(): void
$features = $query->getResult();
$product = $features[0]->getProduct();
- self::assertNotInstanceOf(Proxy::class, $product);
+ self::assertFalse($this->isUninitializedObject($product));
self::assertInstanceOf(ECommerceProduct::class, $product);
self::assertSame('Doctrine Cookbook', $product->getName());
diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php
index 74cc08c5a39..007d0180d82 100644
--- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php
@@ -5,7 +5,6 @@
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Mapping\ClassMetadata;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -98,7 +97,7 @@ public function testInverseSideIsNeverLazy(): void
self::assertNull($customer->getMentor());
self::assertInstanceOf(ECommerceCart::class, $customer->getCart());
- self::assertNotInstanceOf(Proxy::class, $customer->getCart());
+ self::assertFalse($this->isUninitializedObject($customer->getCart()));
self::assertEquals('paypal', $customer->getCart()->getPayment());
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
index 5692dad1697..bfeb802de01 100644
--- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php
@@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -51,7 +50,7 @@ public function testEagerLoadOneToOneOwningSide(): void
$this->getQueryLog()->reset()->enable();
$train = $this->_em->find($train::class, $train->id);
- self::assertNotInstanceOf(Proxy::class, $train->driver);
+ self::assertFalse($this->isUninitializedObject($train->driver));
self::assertEquals('Benjamin', $train->driver->name);
$this->assertQueryCount(1);
@@ -69,7 +68,6 @@ public function testEagerLoadOneToOneNullOwningSide(): void
$this->getQueryLog()->reset()->enable();
$train = $this->_em->find($train::class, $train->id);
- self::assertNotInstanceOf(Proxy::class, $train->driver);
self::assertNull($train->driver);
$this->assertQueryCount(1);
@@ -87,9 +85,9 @@ public function testEagerLoadOneToOneInverseSide(): void
$this->getQueryLog()->reset()->enable();
- $driver = $this->_em->find($owner::class, $owner->id);
- self::assertNotInstanceOf(Proxy::class, $owner->train);
- self::assertNotNull($owner->train);
+ $this->_em->find($owner::class, $owner->id);
+ self::assertFalse($this->isUninitializedObject($owner->train));
+ self::assertInstanceOf(Train::class, $owner->train);
$this->assertQueryCount(1);
}
@@ -108,7 +106,6 @@ public function testEagerLoadOneToOneNullInverseSide(): void
$this->getQueryLog()->reset()->enable();
$driver = $this->_em->find($driver::class, $driver->id);
- self::assertNotInstanceOf(Proxy::class, $driver->train);
self::assertNull($driver->train);
$this->assertQueryCount(1);
@@ -125,8 +122,8 @@ public function testEagerLoadManyToOne(): void
$this->_em->clear();
$waggon = $this->_em->find($waggon::class, $waggon->id);
- self::assertNotInstanceOf(Proxy::class, $waggon->train);
- self::assertNotNull($waggon->train);
+ self::assertFalse($this->isUninitializedObject($waggon->train));
+ self::assertInstanceOf(Train::class, $waggon->train);
}
#[Group('non-cacheable')]
diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php
index 2cc0c153032..547682086f2 100644
--- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php
@@ -11,7 +11,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -66,7 +65,7 @@ public function testFind(): void
$id = $this->createFixture();
$customer = $this->_em->find(ECommerceCustomer::class, $id);
- self::assertNotInstanceOf(Proxy::class, $customer->getMentor());
+ self::assertFalse($this->isUninitializedObject($customer->getMentor()));
}
public function testEagerLoadsAssociation(): void
diff --git a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php
index 079e11d53ab..b2b3306ea1b 100644
--- a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php
@@ -59,7 +59,7 @@ public function testPersistUpdate(): void
{
// Considering case (a)
$proxy = $this->_em->getProxyFactory()->getProxy(CmsUser::class, ['id' => 123]);
- $proxy->__setInitialized(true);
+
$proxy->id = null;
$proxy->username = 'ocra';
$proxy->name = 'Marco';
@@ -84,7 +84,7 @@ public function testEntityWithIdentifier(): void
$this->_em->persist($uninitializedProxy);
$this->_em->flush();
- self::assertFalse($uninitializedProxy->__isInitialized(), 'Proxy didn\'t get initialized during flush operations');
+ self::assertTrue($this->isUninitializedObject($uninitializedProxy), 'Proxy didn\'t get initialized during flush operations');
self::assertEquals($userId, $uninitializedProxy->getId());
$this->_em->remove($uninitializedProxy);
$this->_em->flush();
diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php
index 1766d074ae6..00efce3f080 100644
--- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php
@@ -12,7 +12,6 @@
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\UnexpectedResultException;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\IterableTester;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
@@ -541,8 +540,7 @@ public function testEntityParameters(): void
self::assertEquals(1, count($result));
self::assertInstanceOf(CmsArticle::class, $result[0]);
self::assertEquals('dr. dolittle', $result[0]->topic);
- self::assertInstanceOf(Proxy::class, $result[0]->user);
- self::assertFalse($result[0]->user->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($result[0]->user));
}
#[Group('DDC-952')]
@@ -570,7 +568,7 @@ public function testEnableFetchEagerMode(): void
self::assertCount(10, $articles);
foreach ($articles as $article) {
- self::assertNotInstanceOf(Proxy::class, $article);
+ self::assertFalse($this->isUninitializedObject($article));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php
index 36537512ffa..894a5064c88 100644
--- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php
@@ -6,7 +6,7 @@
use Doctrine\Common\Proxy\Proxy as CommonProxy;
use Doctrine\Common\Util\ClassUtils;
-use Doctrine\Persistence\Proxy;
+use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\Tests\Models\Company\CompanyAuction;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\Models\ECommerce\ECommerceShipping;
@@ -120,9 +120,9 @@ public function testInitializeProxy(): void
$entity = $this->_em->getReference(ECommerceProduct::class, $id);
assert($entity instanceof ECommerceProduct);
- self::assertFalse($entity->__isInitialized(), 'Pre-Condition: Object is unitialized proxy.');
+ self::assertTrue($this->isUninitializedObject($entity), 'Pre-Condition: Object is unitialized proxy.');
$this->_em->getUnitOfWork()->initializeObject($entity);
- self::assertTrue($entity->__isInitialized(), 'Should be initialized after called UnitOfWork::initializeObject()');
+ self::assertFalse($this->isUninitializedObject($entity), 'Should be initialized after called UnitOfWork::initializeObject()');
}
#[Group('DDC-1163')]
@@ -167,9 +167,9 @@ public function testDoNotInitializeProxyOnGettingTheIdentifier(): void
$entity = $this->_em->getReference(ECommerceProduct::class, $id);
assert($entity instanceof ECommerceProduct);
- self::assertFalse($entity->__isInitialized(), 'Pre-Condition: Object is unitialized proxy.');
+ self::assertTrue($this->isUninitializedObject($entity), 'Pre-Condition: Object is unitialized proxy.');
self::assertEquals($id, $entity->getId());
- self::assertFalse($entity->__isInitialized(), "Getting the identifier doesn't initialize the proxy.");
+ self::assertTrue($this->isUninitializedObject($entity), "Getting the identifier doesn't initialize the proxy.");
}
#[Group('DDC-1625')]
@@ -180,9 +180,9 @@ public function testDoNotInitializeProxyOnGettingTheIdentifierDDC1625(): void
$entity = $this->_em->getReference(CompanyAuction::class, $id);
assert($entity instanceof CompanyAuction);
- self::assertFalse($entity->__isInitialized(), 'Pre-Condition: Object is unitialized proxy.');
+ self::assertTrue($this->isUninitializedObject($entity), 'Pre-Condition: Object is unitialized proxy.');
self::assertEquals($id, $entity->getId());
- self::assertFalse($entity->__isInitialized(), "Getting the identifier doesn't initialize the proxy when extending.");
+ self::assertTrue($this->isUninitializedObject($entity), "Getting the identifier doesn't initialize the proxy when extending.");
}
public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightType(): void
@@ -202,10 +202,10 @@ public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightT
$product = $this->_em->getRepository(ECommerceProduct::class)->find($product->getId());
$entity = $product->getShipping();
- self::assertFalse($entity->__isInitialized(), 'Pre-Condition: Object is unitialized proxy.');
+ self::assertTrue($this->isUninitializedObject($entity), 'Pre-Condition: Object is unitialized proxy.');
self::assertEquals($id, $entity->getId());
self::assertSame($id, $entity->getId(), "Check that the id's are the same value, and type.");
- self::assertFalse($entity->__isInitialized(), "Getting the identifier doesn't initialize the proxy.");
+ self::assertTrue($this->isUninitializedObject($entity), "Getting the identifier doesn't initialize the proxy.");
}
public function testInitializeProxyOnGettingSomethingOtherThanTheIdentifier(): void
@@ -215,9 +215,9 @@ public function testInitializeProxyOnGettingSomethingOtherThanTheIdentifier(): v
$entity = $this->_em->getReference(ECommerceProduct::class, $id);
assert($entity instanceof ECommerceProduct);
- self::assertFalse($entity->__isInitialized(), 'Pre-Condition: Object is unitialized proxy.');
+ self::assertTrue($this->isUninitializedObject($entity), 'Pre-Condition: Object is unitialized proxy.');
self::assertEquals('Doctrine Cookbook', $entity->getName());
- self::assertTrue($entity->__isInitialized(), 'Getting something other than the identifier initializes the proxy.');
+ self::assertFalse($this->isUninitializedObject($entity), 'Getting something other than the identifier initializes the proxy.');
}
#[Group('DDC-1604')]
@@ -229,8 +229,8 @@ public function testCommonPersistenceProxy(): void
assert($entity instanceof ECommerceProduct);
$className = ClassUtils::getClass($entity);
- self::assertInstanceOf(Proxy::class, $entity);
- self::assertFalse($entity->__isInitialized());
+ self::assertInstanceOf(InternalProxy::class, $entity);
+ self::assertTrue($this->isUninitializedObject($entity));
self::assertEquals(ECommerceProduct::class, $className);
$restName = str_replace($this->_em->getConfiguration()->getProxyNamespace(), '', $entity::class);
@@ -239,6 +239,6 @@ public function testCommonPersistenceProxy(): void
self::assertTrue(file_exists($proxyFileName), 'Proxy file name cannot be found generically.');
$entity->__load();
- self::assertTrue($entity->__isInitialized());
+ self::assertFalse($this->isUninitializedObject($entity));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php
index 672495ba706..e2dec649342 100644
--- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php
@@ -11,9 +11,9 @@
use Doctrine\ORM\Cache\Exception\CacheException;
use Doctrine\ORM\Cache\QueryCacheEntry;
use Doctrine\ORM\Cache\QueryCacheKey;
+use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\ResultSetMapping;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\Cache\Attraction;
use Doctrine\Tests\Models\Cache\City;
use Doctrine\Tests\Models\Cache\Country;
@@ -939,7 +939,7 @@ public function testResolveAssociationCacheEntry(): void
self::assertNotNull($state1->getCountry());
$this->assertQueryCount(1);
self::assertInstanceOf(State::class, $state1);
- self::assertInstanceOf(Proxy::class, $state1->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $state1->getCountry());
self::assertEquals($countryName, $state1->getCountry()->getName());
self::assertEquals($stateId, $state1->getId());
@@ -957,7 +957,7 @@ public function testResolveAssociationCacheEntry(): void
self::assertNotNull($state2->getCountry());
$this->assertQueryCount(0);
self::assertInstanceOf(State::class, $state2);
- self::assertInstanceOf(Proxy::class, $state2->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $state2->getCountry());
self::assertEquals($countryName, $state2->getCountry()->getName());
self::assertEquals($stateId, $state2->getId());
}
@@ -1031,7 +1031,7 @@ public function testResolveToManyAssociationCacheEntry(): void
$this->assertQueryCount(1);
self::assertInstanceOf(State::class, $state1);
- self::assertInstanceOf(Proxy::class, $state1->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $state1->getCountry());
self::assertInstanceOf(City::class, $state1->getCities()->get(0));
self::assertInstanceOf(State::class, $state1->getCities()->get(0)->getState());
self::assertSame($state1, $state1->getCities()->get(0)->getState());
@@ -1048,7 +1048,7 @@ public function testResolveToManyAssociationCacheEntry(): void
$this->assertQueryCount(0);
self::assertInstanceOf(State::class, $state2);
- self::assertInstanceOf(Proxy::class, $state2->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $state2->getCountry());
self::assertInstanceOf(City::class, $state2->getCities()->get(0));
self::assertInstanceOf(State::class, $state2->getCities()->get(0)->getState());
self::assertSame($state2, $state2->getCities()->get(0)->getState());
diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php
index 95c48b74bc6..7ed7732526c 100644
--- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php
@@ -4,7 +4,7 @@
namespace Doctrine\Tests\ORM\Functional;
-use Doctrine\Persistence\Proxy;
+use Doctrine\ORM\Proxy\InternalProxy;
use Doctrine\Tests\Models\Cache\Country;
use Doctrine\Tests\Models\Cache\State;
use PHPUnit\Framework\Attributes\Group;
@@ -198,8 +198,8 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[0]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[1]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());
// load from cache
$this->getQueryLog()->reset()->enable();
@@ -212,8 +212,8 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[0]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[1]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());
// invalidate cache
$this->_em->persist(new State('foo', $this->_em->find(Country::class, $this->countries[0]->getId())));
@@ -231,8 +231,8 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[0]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[1]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());
// load from cache
$this->getQueryLog()->reset()->enable();
@@ -245,7 +245,7 @@ public function testRepositoryCacheFindAllToOneAssociation(): void
self::assertInstanceOf(State::class, $entities[1]);
self::assertInstanceOf(Country::class, $entities[0]->getCountry());
self::assertInstanceOf(Country::class, $entities[1]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[0]->getCountry());
- self::assertInstanceOf(Proxy::class, $entities[1]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[0]->getCountry());
+ self::assertInstanceOf(InternalProxy::class, $entities[1]->getCountry());
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php
index 33648abb103..f3fa00560d2 100644
--- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php
@@ -7,7 +7,6 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\MatchingAssociationFieldRequiresObject;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\Company\CompanyContract;
use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\Models\Company\CompanyFixContract;
@@ -391,13 +390,14 @@ public function testGetReferenceEntityWithSubclasses(): void
$this->loadFullFixture();
$ref = $this->_em->getReference(CompanyContract::class, $this->fix->getId());
- self::assertNotInstanceOf(Proxy::class, $ref, 'Cannot Request a proxy from a class that has subclasses.');
+ self::assertFalse($this->isUninitializedObject($ref), 'Cannot Request a proxy from a class that has subclasses.');
self::assertInstanceOf(CompanyContract::class, $ref);
self::assertInstanceOf(CompanyFixContract::class, $ref, 'Direct fetch of the reference has to load the child class Employee directly.');
$this->_em->clear();
$ref = $this->_em->getReference(CompanyFixContract::class, $this->fix->getId());
- self::assertInstanceOf(Proxy::class, $ref, 'A proxy can be generated only if no subclasses exists for the requested reference.');
+
+ self::assertTrue($this->isUninitializedObject($ref), 'A proxy can be generated only if no subclasses exists for the requested reference.');
}
#[Group('DDC-952')]
@@ -411,6 +411,6 @@ public function testEagerLoadInheritanceHierarchy(): void
->setParameter(1, $this->fix->getId())
->getSingleResult();
- self::assertNotInstanceOf(Proxy::class, $contract->getSalesPerson());
+ self::assertFalse($this->isUninitializedObject($contract->getSalesPerson()));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
index 7a32c6bde08..c038908e696 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
@@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -89,7 +88,7 @@ private function setPropertyAndAssignTagToSpecialProduct(): void
assert($specialProduct instanceof DDC1163SpecialProduct);
self::assertInstanceOf(DDC1163SpecialProduct::class, $specialProduct);
- self::assertInstanceOf(Proxy::class, $specialProduct);
+ self::assertTrue($this->isUninitializedObject($specialProduct));
$specialProduct->setSubclassProperty('foobar');
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
index 725e79e4d2b..28f6073614e 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
@@ -44,7 +44,7 @@ public function testIssue(): void
$company = $this->_em->find($company::class, $companyId);
self::assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company), 'Company is in identity map.');
- self::assertFalse($company->member->__isInitialized(), 'Pre-Condition');
+ self::assertTrue($this->isUninitializedObject($company->member), 'Pre-Condition');
self::assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company->member), 'Member is in identity map.');
$this->_em->remove($company);
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php
index ba48333ae5b..3f77bace8eb 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php
@@ -37,9 +37,9 @@ public function testOneToOnePersist(): void
$user = $this->_em->find(DDC1228User::class, $user->id);
- self::assertFalse($user->getProfile()->__isInitialized(), 'Proxy is not initialized');
+ self::assertTrue($this->isUninitializedObject($user->getProfile()), 'Proxy is not initialized');
$user->getProfile()->setName('Bar');
- self::assertTrue($user->getProfile()->__isInitialized(), 'Proxy is not initialized');
+ self::assertFalse($this->isUninitializedObject($user->getProfile()), 'Proxy is not initialized');
self::assertEquals('Bar', $user->getProfile()->getName());
self::assertEquals(['id' => 1, 'name' => 'Foo'], $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile()));
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php
index 885f82a024c..2d44baf3383 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php
@@ -12,7 +12,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -55,7 +54,7 @@ public function testIssue(): void
$results = $this->_em->createQuery($dql)->setMaxResults(1)->getResult();
self::assertSame($results[0], $results[0]->entitiesB[0]->entityAFrom);
- self::assertNotInstanceOf(Proxy::class, $results[0]->entitiesB[0]->entityATo);
+ self::assertFalse($this->isUninitializedObject($results[0]->entitiesB[0]->entityATo));
self::assertInstanceOf(Collection::class, $results[0]->entitiesB[0]->entityATo->getEntitiesB());
}
@@ -83,12 +82,12 @@ public function testFetchJoinOneToOneFromInverse(): void
$data = $this->_em->createQuery($dql)->getResult();
$this->_em->clear();
- self::assertNotInstanceOf(Proxy::class, $data[0]->user);
+ self::assertFalse($this->isUninitializedObject($data[0]->user));
$dql = 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.address a';
$data = $this->_em->createQuery($dql)->getResult();
- self::assertNotInstanceOf(Proxy::class, $data[0]->address);
+ self::assertFalse($this->isUninitializedObject($data[0]->address));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php
index 61a7ae45239..1f96942df10 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php
@@ -12,7 +12,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -64,16 +63,15 @@ public function testIssue(): void
$address = $this->_em->find(DDC2306Address::class, $address->id);
assert($address instanceof DDC2306Address);
$user = $address->users->first()->user;
- assert($user instanceof DDC2306User || $user instanceof Proxy);
- self::assertInstanceOf(Proxy::class, $user);
+ $this->assertTrue($this->isUninitializedObject($user));
self::assertInstanceOf(DDC2306User::class, $user);
$userId = $user->id;
self::assertNotNull($userId);
- $user->__load();
+ $this->_em->getUnitOfWork()->initializeObject($user);
self::assertEquals(
$userId,
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php
index 9950823c57d..085d4f4d4df 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php
@@ -11,7 +11,6 @@
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\Table;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
class DDC237Test extends OrmFunctionalTestCase
@@ -48,16 +47,14 @@ public function testUninitializedProxyIsInitializedOnFetchJoin(): void
$this->_em->clear();
$x2 = $this->_em->find($x::class, $x->id); // proxy injected for Y
- self::assertInstanceOf(Proxy::class, $x2->y);
- self::assertFalse($x2->y->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($x2->y));
// proxy for Y is in identity map
$z2 = $this->_em->createQuery('select z,y from ' . $z::class . ' z join z.y y where z.id = ?1')
->setParameter(1, $z->id)
->getSingleResult();
- self::assertInstanceOf(Proxy::class, $z2->y);
- self::assertTrue($z2->y->__isInitialized());
+ self::assertFalse($this->isUninitializedObject($z2->y));
self::assertEquals('Y', $z2->y->data);
self::assertEquals($y->id, $z2->y->id);
@@ -67,7 +64,6 @@ public function testUninitializedProxyIsInitializedOnFetchJoin(): void
self::assertNotSame($x, $x2);
self::assertNotSame($z, $z2);
self::assertSame($z2->y, $x2->y);
- self::assertInstanceOf(Proxy::class, $z2->y);
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php
index ef2906c2b12..a83be2af1f3 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php
@@ -15,7 +15,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\Table;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -60,21 +59,20 @@ public function testIssue(): void
$this->getQueryLog()->reset()->enable();
- self::assertInstanceOf(Proxy::class, $item->getCurrency());
- self::assertFalse($item->getCurrency()->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($item->getCurrency()));
self::assertArrayHasKey('convertToPHPValue', DDC2494TinyIntType::$calls);
self::assertCount(1, DDC2494TinyIntType::$calls['convertToPHPValue']);
self::assertIsInt($item->getCurrency()->getId());
self::assertCount(1, DDC2494TinyIntType::$calls['convertToPHPValue']);
- self::assertFalse($item->getCurrency()->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($item->getCurrency()));
$this->assertQueryCount(0);
self::assertIsInt($item->getCurrency()->getTemp());
self::assertCount(3, DDC2494TinyIntType::$calls['convertToPHPValue']);
- self::assertTrue($item->getCurrency()->__isInitialized());
+ self::assertFalse($this->isUninitializedObject($item->getCurrency()));
$this->assertQueryCount(1);
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php
index 89d02b56208..b8dfba13b9c 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php
@@ -4,7 +4,6 @@
namespace Doctrine\Tests\ORM\Functional\Ticket;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\Legacy\LegacyUser;
use Doctrine\Tests\Models\Legacy\LegacyUserReference;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -37,15 +36,10 @@ public function testIssue(): void
self::assertInstanceOf(LegacyUser::class, $result[1]->source());
self::assertInstanceOf(LegacyUser::class, $result[1]->target());
- self::assertInstanceOf(Proxy::class, $result[0]->source());
- self::assertInstanceOf(Proxy::class, $result[0]->target());
- self::assertInstanceOf(Proxy::class, $result[1]->source());
- self::assertInstanceOf(Proxy::class, $result[1]->target());
-
- self::assertFalse($result[0]->target()->__isInitialized());
- self::assertFalse($result[0]->source()->__isInitialized());
- self::assertFalse($result[1]->target()->__isInitialized());
- self::assertFalse($result[1]->source()->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($result[0]->target()));
+ self::assertTrue($this->isUninitializedObject($result[0]->source()));
+ self::assertTrue($this->isUninitializedObject($result[1]->target()));
+ self::assertTrue($this->isUninitializedObject($result[1]->source()));
self::assertNotNull($result[0]->source()->getId());
self::assertNotNull($result[0]->target()->getId());
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php
index 942952c1610..ed185ad873d 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php
@@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Query;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -52,7 +51,7 @@ public function testIssue(): void
->getResult();
self::assertCount(1, $children);
- self::assertNotInstanceOf(Proxy::class, $children[0]->parent);
+ self::assertFalse($this->isUninitializedObject($children[0]->parent));
self::assertFalse($children[0]->parent->children->isInitialized());
self::assertEquals(0, $children[0]->parent->children->unwrap()->count());
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php
index 836db507267..4fc79b04d06 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php
@@ -10,7 +10,6 @@
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -51,7 +50,7 @@ public function testJoinColumnWithSameNameAsAssociationField(): void
self::assertInstanceOf(DDC522Cart::class, $r[0]);
self::assertInstanceOf(DDC522Customer::class, $r[0]->customer);
- self::assertNotInstanceOf(Proxy::class, $r[0]->customer);
+ self::assertFalse($this->isUninitializedObject($r[0]->customer));
self::assertEquals('name', $r[0]->customer->name);
$fkt = new DDC522ForeignKeyTest();
@@ -63,8 +62,7 @@ public function testJoinColumnWithSameNameAsAssociationField(): void
$fkt2 = $this->_em->find($fkt::class, $fkt->id);
self::assertEquals($fkt->cart->id, $fkt2->cartId);
- self::assertInstanceOf(Proxy::class, $fkt2->cart);
- self::assertFalse($fkt2->cart->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($fkt2->cart));
}
#[Group('DDC-522')]
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php
index 7785711c7df..adb3cbcf35a 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php
@@ -16,7 +16,6 @@
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
class DDC531Test extends OrmFunctionalTestCase
@@ -46,7 +45,7 @@ public function testIssue(): void
// parent will already be loaded, cannot be lazy because it has mapped subclasses and we would not
// know which proxy type to put in.
self::assertInstanceOf(DDC531Item::class, $item3->parent);
- self::assertNotInstanceOf(Proxy::class, $item3->parent);
+ self::assertFalse($this->isUninitializedObject($item3->parent));
$item4 = $this->_em->find(DDC531Item::class, $item1->id); // Load parent item (id 1)
self::assertNull($item4->parent);
self::assertNotNull($item4->getChildren());
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php
index 68d3671ec1b..75fbc5ee60a 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php
@@ -9,7 +9,6 @@
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -43,7 +42,7 @@ public function testOneToOneEager(): void
$eagerAppointment = $this->_em->find(DDC633Appointment::class, $app->id);
// Eager loading of one to one leads to fetch-join
- self::assertNotInstanceOf(Proxy::class, $eagerAppointment->patient);
+ self::assertFalse($this->isUninitializedObject($eagerAppointment->patient));
self::assertTrue($this->_em->contains($eagerAppointment->patient));
}
@@ -67,8 +66,7 @@ public function testDQLDeferredEagerLoad(): void
$appointments = $this->_em->createQuery('SELECT a FROM ' . __NAMESPACE__ . '\DDC633Appointment a')->getResult();
foreach ($appointments as $eagerAppointment) {
- self::assertInstanceOf(Proxy::class, $eagerAppointment->patient);
- self::assertTrue($eagerAppointment->patient->__isInitialized(), 'Proxy should already be initialized due to eager loading!');
+ self::assertFalse($this->isUninitializedObject($eagerAppointment->patient), 'Proxy should already be initialized due to eager loading!');
}
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php
index 1ea108e4330..b0366d1daec 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php
@@ -12,7 +12,6 @@
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -62,11 +61,10 @@ public function testInlineEmbeddableProxyInitialization(): void
$secondEntityWithLazyParameter = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1);
- self::assertInstanceOf(Proxy::class, $secondEntityWithLazyParameter->lazyLoaded);
self::assertInstanceOf(DDC6460Entity::class, $secondEntityWithLazyParameter->lazyLoaded);
- self::assertFalse($secondEntityWithLazyParameter->lazyLoaded->__isInitialized());
+ self::assertTrue($this->isUninitializedObject($secondEntityWithLazyParameter->lazyLoaded));
self::assertEquals($secondEntityWithLazyParameter->lazyLoaded->embedded, $entity->embedded);
- self::assertTrue($secondEntityWithLazyParameter->lazyLoaded->__isInitialized());
+ self::assertFalse($this->isUninitializedObject($secondEntityWithLazyParameter->lazyLoaded));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php
index a13ce909739..08c41e3a2eb 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php
@@ -8,7 +8,6 @@
use Doctrine\ORM\Query\AST\SelectExpression;
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\ORM\Query\TreeWalkerAdapter;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -47,7 +46,7 @@ public function testReorderEntityFetchJoinForHydration(): void
unset($result[0]);
self::assertInstanceOf(ECommerceCart::class, $cart2);
- self::assertNotInstanceOf(Proxy::class, $cart2->getCustomer());
+ self::assertFalse($this->isUninitializedObject($cart2->getCustomer()));
self::assertInstanceOf(ECommerceCustomer::class, $cart2->getCustomer());
self::assertEquals(['name' => 'roman', 'payment' => 'cash'], $result);
}
@@ -76,7 +75,7 @@ public function testDqlTreeWalkerReordering(): void
$cart2 = $result[0][0];
assert($cart2 instanceof ECommerceCart);
- self::assertInstanceOf(Proxy::class, $cart2->getCustomer());
+ self::assertTrue($this->isUninitializedObject($cart2->getCustomer()));
}
}
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php
index e0fa6212f2b..a2e1b2c0751 100644
--- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php
@@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\PersistentCollection;
-use Doctrine\Persistence\Proxy;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
@@ -88,8 +87,8 @@ public function testIssue(): void
$calls = $this->_em->createQuery($dql)->getResult();
self::assertCount(2, $calls);
- self::assertNotInstanceOf(Proxy::class, $calls[0]->getPhoneNumber());
- self::assertNotInstanceOf(Proxy::class, $calls[1]->getPhoneNumber());
+ self::assertFalse($this->isUninitializedObject($calls[0]->getPhoneNumber()));
+ self::assertFalse($this->isUninitializedObject($calls[1]->getPhoneNumber()));
$dql = 'SELECT p, c FROM ' . DDC881PhoneNumber::class . ' p JOIN p.calls c';
$numbers = $this->_em->createQuery($dql)->getResult();
diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php
index a49afe72ab4..ca3d430c83c 100644
--- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php
+++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php
@@ -1104,4 +1104,9 @@ protected function dropAndCreateTable(Table $table): void
$this->dropTableIfExists($tableName);
$schemaManager->createTable($table);
}
+
+ final protected function isUninitializedObject(object $entity): bool
+ {
+ return $this->_em->getUnitOfWork()->isUninitializedObject($entity);
+ }
}