diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 56cd905e1..51c2fa352 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -34,6 +34,8 @@ jobs: - "highest" symfony-version: - "stable" + proxy: + - "lazy-ghost" include: # Test against lowest dependencies - dependencies: "lowest" @@ -42,6 +44,7 @@ jobs: driver-version: "1.17.0" topology: "server" symfony-version: "stable" + proxy: "lazy-ghost" # Test with highest dependencies - topology: "server" php-version: "8.2" @@ -49,6 +52,7 @@ jobs: driver-version: "stable" dependencies: "highest" symfony-version: "7" + proxy: "lazy-ghost" # Test with a 5.0 replica set - topology: "replica_set" php-version: "8.2" @@ -56,6 +60,14 @@ jobs: driver-version: "stable" dependencies: "highest" symfony-version: "stable" + proxy: "lazy-ghost" + # Test with ProxyManager + - php-version: "8.2" + mongodb-version: "5.0" + driver-version: "stable" + dependencies: "highest" + symfony-version: "stable" + proxy: "proxy-manager" # Test with a 5.0 sharded cluster # Currently disabled due to a bug where MongoDB reports "sharding status unknown" # - topology: "sharded_cluster" @@ -64,6 +76,7 @@ jobs: # driver-version: "stable" # dependencies: "highest" # symfony-version: "stable" +# proxy: "lazy-ghost" steps: - name: "Checkout" @@ -118,6 +131,13 @@ jobs: # https://github.com/vimeo/psalm/pull/10928 composer remove --no-update --dev vimeo/psalm + - name: "Remove proxy-manager-lts" + if: "${{ matrix.lazy-ghost == 'true' }}" + run: | + # proxy-manager-lts is not installed by default and must not be used + # unless explicitly requested + composer remove --no-update --dev friendsofphp/proxy-manager-lts + - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v3" with: @@ -134,3 +154,4 @@ jobs: run: "vendor/bin/phpunit" env: DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }} + USE_LAZY_GHOST_OBJECTS: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}" diff --git a/composer.json b/composer.json index c1d762040..3ed8c5c0d 100644 --- a/composer.json +++ b/composer.json @@ -28,20 +28,20 @@ "doctrine/event-manager": "^1.0 || ^2.0", "doctrine/instantiator": "^1.1 || ^2", "doctrine/persistence": "^3.2", - "friendsofphp/proxy-manager-lts": "^1.0", "jean85/pretty-package-versions": "^1.3.0 || ^2.0.1", "mongodb/mongodb": "^1.17.0", "psr/cache": "^1.0 || ^2.0 || ^3.0", "symfony/console": "^5.4 || ^6.0 || ^7.0", "symfony/deprecation-contracts": "^2.2 || ^3.0", "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", - "symfony/var-exporter": "^5.4 || ^6.0 || ^7.0" + "symfony/var-exporter": "^6.2 || ^7.0" }, "require-dev": { "ext-bcmath": "*", "doctrine/annotations": "^1.12 || ^2.0", "doctrine/coding-standard": "^12.0", "doctrine/orm": "^3.2", + "friendsofphp/proxy-manager-lts": "^1.0", "jmikola/geojson": "^1.0", "phpbench/phpbench": "^1.0.0", "phpstan/phpstan": "~1.10.67", diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index 8de0ab1ad..768d32b9b 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -24,6 +24,7 @@ use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\ObjectRepository; use InvalidArgumentException; +use LogicException; use MongoDB\Driver\WriteConcern; use ProxyManager\Configuration as ProxyManagerConfiguration; use ProxyManager\Factory\LazyLoadingGhostFactory; @@ -33,6 +34,7 @@ use ReflectionClass; use function array_key_exists; +use function class_exists; use function interface_exists; use function trigger_deprecation; use function trim; @@ -128,6 +130,8 @@ class Configuration private bool $useTransactionalFlush = false; + private bool $useLazyGhostObject = true; + /** * Adds a namespace under a certain alias. */ @@ -613,6 +617,32 @@ public function isTransactionalFlushEnabled(): bool { return $this->useTransactionalFlush; } + + /** + * Generate proxy classes using Symfony VarExporter's LazyGhostTrait if true. + * Otherwise, use ProxyManager's LazyLoadingGhostFactory (deprecated) + */ + public function setUseLazyGhostObject(bool $flag): void + { + if ($flag === false) { + if (! class_exists(ProxyManagerConfiguration::class)) { + throw new LogicException('Package "friendsofphp/proxy-manager-lts" is required to disable LazyGhostObject.'); + } + + trigger_deprecation( + 'doctrine/mongodb-odm', + '2.6', + 'Using "friendsofphp/proxy-manager-lts" is deprecated. Use "symfony/var-exporter" LazyGhostObjects instead.', + ); + } + + $this->useLazyGhostObject = $flag; + } + + public function isLazyGhostObjectEnabled(): bool + { + return $this->useLazyGhostObject ?? true; + } } interface_exists(MappingDriver::class); diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index 61e421c65..69e81954f 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -11,9 +11,11 @@ use Doctrine\ODM\MongoDB\Mapping\MappingException; use Doctrine\ODM\MongoDB\Proxy\Factory\LazyGhostProxyFactory; use Doctrine\ODM\MongoDB\Proxy\Factory\ProxyFactory; +use Doctrine\ODM\MongoDB\Proxy\Factory\StaticProxyFactory; use Doctrine\ODM\MongoDB\Proxy\Resolver\CachingClassNameResolver; use Doctrine\ODM\MongoDB\Proxy\Resolver\ClassNameResolver; use Doctrine\ODM\MongoDB\Proxy\Resolver\LazyGhostProxyClassNameResolver; +use Doctrine\ODM\MongoDB\Proxy\Resolver\ProxyManagerClassNameResolver; use Doctrine\ODM\MongoDB\Query\FilterCollection; use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Repository\GridFSRepository; @@ -156,7 +158,9 @@ protected function __construct(?Client $client = null, ?Configuration $config = ], ); - $this->classNameResolver = new CachingClassNameResolver(new LazyGhostProxyClassNameResolver()); + $this->classNameResolver = $config->isLazyGhostObjectEnabled() + ? new CachingClassNameResolver(new LazyGhostProxyClassNameResolver()) + : new CachingClassNameResolver(new ProxyManagerClassNameResolver($this->config)); $metadataFactoryClassName = $this->config->getClassMetadataFactoryName(); $this->metadataFactory = new $metadataFactoryClassName(); @@ -181,7 +185,9 @@ protected function __construct(?Client $client = null, ?Configuration $config = $this->unitOfWork = new UnitOfWork($this, $this->eventManager, $this->hydratorFactory); $this->schemaManager = new SchemaManager($this, $this->metadataFactory); - $this->proxyFactory = new LazyGhostProxyFactory($this, $config->getProxyDir(), $config->getProxyNamespace(), $config->getAutoGenerateProxyClasses()); + $this->proxyFactory = $config->isLazyGhostObjectEnabled() + ? new LazyGhostProxyFactory($this, $config->getProxyDir(), $config->getProxyNamespace(), $config->getAutoGenerateProxyClasses()) + : new StaticProxyFactory($this); $this->repositoryFactory = $this->config->getRepositoryFactory(); } diff --git a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/LazyGhostProxyFactory.php b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/LazyGhostProxyFactory.php index 691b6a769..d22534c60 100644 --- a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/LazyGhostProxyFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/LazyGhostProxyFactory.php @@ -84,7 +84,7 @@ public function __serialize(): array private readonly UnitOfWork $uow; /** @var Configuration::AUTOGENERATE_* */ - private $autoGenerate; + private int $autoGenerate; /** @var array */ private array $proxyFactories = []; diff --git a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php index 8200a4fe2..5e5972adb 100644 --- a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php @@ -23,7 +23,7 @@ /** * This factory is used to create proxy objects for documents at runtime. * - * @deprecated + * @deprecated since 2.10, use LazyGhostProxyFactory instead */ final class StaticProxyFactory implements ProxyFactory { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c16a73401..3860390bd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,5 +29,6 @@ + diff --git a/tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php b/tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php index 204fb9e7b..622ff8603 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests; +use Composer\InstalledVersions; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; @@ -89,6 +90,7 @@ protected static function getConfiguration(): Configuration $config->setPersistentCollectionNamespace('PersistentCollections'); $config->setDefaultDB(DOCTRINE_MONGODB_DATABASE); $config->setMetadataDriverImpl(static::createMetadataDriverImpl()); + $config->setUseLazyGhostObject((bool) $_ENV['USE_LAZY_GHOST_OBJECTS']); $config->addFilter('testFilter', Filter::class); $config->addFilter('testFilter2', Filter::class); @@ -118,10 +120,14 @@ public static function assertArraySubset(array $subset, array $array, bool $chec public static function assertIsLazyObject(object $document): void { - self::logicalOr( - self::isInstanceOf(InternalProxy::class), - self::isInstanceOf(LazyLoadingInterface::class), - )->evaluate($document); + if (InstalledVersions::isInstalled('friendsofphp/proxy-manager')) { + self::logicalOr( + self::isInstanceOf(InternalProxy::class), + self::isInstanceOf(LazyLoadingInterface::class), + )->evaluate($document); + } else { + self::assertInstanceOf(InternalProxy::class, $document); + } } protected static function createMetadataDriverImpl(): MappingDriver diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php index 0b60b4487..24da4f568 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php @@ -4,7 +4,6 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use Documents\Event; use Documents\User; @@ -30,7 +29,7 @@ public function testGetIdentifierValue(): void $userTest = $test->getUser(); self::assertEquals($user->getId(), $userTest->getId()); - self::assertInstanceOf(InternalProxy::class, $userTest); + self::assertIsLazyObject($userTest); self::assertTrue($this->uow->isUninitializedObject($userTest)); $this->dm->clear(); @@ -42,7 +41,7 @@ public function testGetIdentifierValue(): void $foundUser = $test->getUser(); self::assertEquals($user->getId(), $class->getIdentifierValue($user)); self::assertEquals($user->getId(), $class->getFieldValue($foundUser, 'id')); - self::assertInstanceOf(InternalProxy::class, $foundUser); + self::assertIsLazyObject($foundUser); self::assertTrue($this->uow->isUninitializedObject($foundUser)); self::assertEquals('jwage', $foundUser->getUsername()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php index f1f59072a..3ffe267e3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php @@ -95,7 +95,7 @@ public function testPrimeReferencesWithDBRefObjects(): void ->field('groups')->prime(true); foreach ($qb->getQuery() as $user) { - self::assertInstanceOf(InternalProxy::class, $user->getAccount()); + self::assertIsLazyObject($user->getAccount()); self::assertFalse($this->uow->isUninitializedObject($user->getAccount())); self::assertCount(2, $user->getGroups()); @@ -133,7 +133,7 @@ public function testPrimeReferencesWithSimpleReferences(): void ->field('users')->prime(true); foreach ($qb->getQuery() as $simpleUser) { - self::assertInstanceOf(InternalProxy::class, $simpleUser->getUser()); + self::assertIsLazyObject($simpleUser->getUser()); self::assertFalse($this->uow->isUninitializedObject($simpleUser->getUser())); self::assertCount(2, $simpleUser->getUsers()); @@ -196,7 +196,7 @@ public function testPrimeReferencesNestedInNamedEmbeddedReference(): void self::assertNotInstanceOf(InternalProxy::class, $embeddedDoc); self::assertInstanceOf(EmbeddedWhichReferences::class, $embeddedDoc); - self::assertInstanceOf(InternalProxy::class, $embeddedDoc->referencedDoc); + self::assertIsLazyObject($embeddedDoc->referencedDoc); self::assertFalse($this->uow->isUninitializedObject($embeddedDoc->referencedDoc)); self::assertCount(2, $embeddedDoc->referencedDocs); @@ -252,7 +252,7 @@ public function testPrimeReferencesWithDifferentStoreAsReferences(): void assert($referenceUser instanceof ReferenceUser); $user = $referenceUser->getUser(); self::assertInstanceOf(User::class, $user); - self::assertInstanceOf(InternalProxy::class, $user); + self::assertIsLazyObject($user); self::assertFalse($this->uow->isUninitializedObject($user)); self::assertCount(1, $referenceUser->getUsers()); @@ -263,7 +263,7 @@ public function testPrimeReferencesWithDifferentStoreAsReferences(): void } $parentUser = $referenceUser->getParentUser(); - self::assertInstanceOf(InternalProxy::class, $parentUser); + self::assertIsLazyObject($parentUser); self::assertInstanceOf(User::class, $parentUser); self::assertFalse($this->uow->isUninitializedObject($parentUser)); @@ -276,7 +276,7 @@ public function testPrimeReferencesWithDifferentStoreAsReferences(): void $otherUser = $referenceUser->getOtherUser(); self::assertInstanceOf(User::class, $otherUser); - self::assertInstanceOf(InternalProxy::class, $otherUser); + self::assertIsLazyObject($otherUser); self::assertFalse($this->uow->isUninitializedObject($otherUser)); self::assertCount(1, $referenceUser->getOtherUsers()); @@ -331,7 +331,7 @@ public function testPrimeReferencesWithDiscriminatedReferenceOne(): void ->field('server')->prime(true); foreach ($qb->getQuery() as $agent) { - self::assertInstanceOf(InternalProxy::class, $agent->server); + self::assertIsLazyObject($agent->server); self::assertFalse($this->uow->isUninitializedObject($agent->server)); } } @@ -523,7 +523,7 @@ public function testPrimeEmbeddedReferenceTwoLevelsDeep(): void $currency = $money->getCurrency(); - self::assertInstanceOf(InternalProxy::class, $currency); + self::assertIsLazyObject($currency); self::assertInstanceOf(Currency::class, $currency); self::assertFalse($this->uow->isUninitializedObject($currency)); } @@ -551,7 +551,7 @@ public function testPrimeReferencesInReferenceMany(): void self::assertInstanceOf(BlogPost::class, $post); $comment = $post->comments->first(); - self::assertInstanceOf(InternalProxy::class, $comment->author); + self::assertIsLazyObject($comment->author); self::assertFalse($this->uow->isUninitializedObject($comment->author)); } @@ -578,7 +578,7 @@ public function testPrimeReferencesInReferenceManyWithRepositoryMethodEager(): v self::assertInstanceOf(BlogPost::class, $post); $comment = $post->repoCommentsWithPrimer->first(); - self::assertInstanceOf(InternalProxy::class, $comment->author); + self::assertIsLazyObject($comment->author); self::assertFalse($this->uow->isUninitializedObject($comment->author)); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php index d28ad801e..7d988507b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php @@ -12,7 +12,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use Documents\Account; use Documents\Address; @@ -81,7 +80,7 @@ public function testLazyLoadReference(): void assert($profile instanceof Profile); self::assertInstanceOf(Profile::class, $profile); - self::assertInstanceOf(InternalProxy::class, $profile); + self::assertIsLazyObject($profile); $profile->getFirstName(); @@ -103,7 +102,7 @@ public function testLazyLoadedWithNotifyPropertyChanged(): void $user = $this->dm->find($user::class, $user->getId()); $profile = $user->getProfileNotify(); - self::assertInstanceOf(InternalProxy::class, $profile); + self::assertIsLazyObject($profile); self::assertTrue($this->uow->isUninitializedObject($profile)); $user->getProfileNotify()->setLastName('Malarz'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php index c0aa3c18d..fac852a6b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php @@ -7,7 +7,6 @@ use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; class GH520Test extends BaseTestCase @@ -29,7 +28,7 @@ public function testPrimeWithGetSingleResult(): void $document = $query->getSingleResult(); self::assertInstanceOf(GH520Document::class, $document); - self::assertInstanceOf(InternalProxy::class, $document->ref); + self::assertIsLazyObject($document->ref); self::assertFalse($this->uow->isUninitializedObject($document->ref)); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php index 0b48112ab..16c361b6b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php @@ -8,7 +8,6 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use function iterator_to_array; @@ -58,11 +57,11 @@ public function testReferenceManyOwningSidePreparesFilterCriteria(): void */ self::assertCount(2, $user1following); - self::assertInstanceOf(InternalProxy::class, $user1following[0]); + self::assertIsLazyObject($user1following[0]); self::assertFalse($this->uow->isUninitializedObject($user1following[0])); self::assertEquals($user2->getId(), $user1following[0]->getId()); - self::assertInstanceOf(InternalProxy::class, $user1following[1]); + self::assertIsLazyObject($user1following[1]); self::assertTrue($this->uow->isUninitializedObject($user1following[1])); self::assertEquals($user3->getId(), $user1following[1]->getId()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php index 356a70da9..9207ae980 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php @@ -8,7 +8,6 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use function iterator_to_array; @@ -49,11 +48,11 @@ public function testReferenceManyOwningSidePreparesFilterCriteriaForDifferentCla */ self::assertCount(2, $user1likes); - self::assertInstanceOf(InternalProxy::class, $user1likes[0]); + self::assertIsLazyObject($user1likes[0]); self::assertFalse($this->uow->isUninitializedObject($user1likes[0])); self::assertEquals($thing1->getId(), $user1likes[0]->getId()); - self::assertInstanceOf(InternalProxy::class, $user1likes[1]); + self::assertIsLazyObject($user1likes[1]); self::assertTrue($this->uow->isUninitializedObject($user1likes[1])); self::assertEquals($thing2->getId(), $user1likes[1]->getId()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php index 8d2927da7..b848f5142 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php @@ -10,7 +10,6 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ODM\MongoDB\Iterator\Iterator; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use MongoDB\BSON\Binary; use PHPUnit\Framework\Attributes\DataProvider; @@ -49,7 +48,7 @@ public function testA(Closure $idGenerator): void self::assertEquals($idGenerator('parent'), $parent->id); self::assertEquals('parent', $parent->name); - self::assertInstanceOf(InternalProxy::class, $parent->refOne); + self::assertIsLazyObject($parent->refOne); self::assertInstanceOf(GH852Document::class, $parent->refOne); self::assertTrue($this->uow->isUninitializedObject($parent->refOne)); self::assertEquals($idGenerator('childA'), $parent->refOne->id); @@ -61,13 +60,13 @@ public function testA(Closure $idGenerator): void /* These proxies will be initialized when we first access the collection * by DocumentPersister::loadReferenceManyCollectionOwningSide(). */ - self::assertInstanceOf(InternalProxy::class, $parent->refMany[0]); + self::assertIsLazyObject($parent->refMany[0]); self::assertInstanceOf(GH852Document::class, $parent->refMany[0]); self::assertFalse($this->uow->isUninitializedObject($parent->refMany[0])); self::assertEquals($idGenerator('childB'), $parent->refMany[0]->id); self::assertEquals('childB', $parent->refMany[0]->name); - self::assertInstanceOf(InternalProxy::class, $parent->refMany[1]); + self::assertIsLazyObject($parent->refMany[1]); self::assertInstanceOf(GH852Document::class, $parent->refMany[1]); self::assertFalse($this->uow->isUninitializedObject($parent->refMany[1])); self::assertEquals($idGenerator('childC'), $parent->refMany[1]->id); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php index 480c8a19e..c465795dc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH936Test.php @@ -7,7 +7,6 @@ use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; use Doctrine\ODM\MongoDB\Events; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; class GH936Test extends BaseTestCase @@ -27,7 +26,7 @@ public function testRemoveCascadesThroughProxyDocuments(): void $foo = $this->dm->find(GH936Document::class, $foo->id); - self::assertInstanceOf(InternalProxy::class, $foo->ref); + self::assertIsLazyObject($foo->ref); $this->dm->remove($foo); $this->dm->flush(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php index 768440338..918e72db7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php @@ -4,7 +4,6 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Repository\ViewRepository; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use Doctrine\ODM\MongoDB\UnitOfWork; @@ -112,7 +111,7 @@ public function testViewReferences(): void $viewReference = $this->dm->find(ViewReference::class, $alcaeus->getId()); self::assertInstanceOf(ViewReference::class, $viewReference); - self::assertInstanceOf(InternalProxy::class, $viewReference->getReferenceOneView()); + self::assertIsLazyObject($viewReference->getReferenceOneView()); self::assertSame($malarzm->getId(), $viewReference->getReferenceOneView()->getId()); // No proxies for inverse referenceOne @@ -120,7 +119,7 @@ public function testViewReferences(): void self::assertSame($alcaeus->getId(), $viewReference->getReferenceOneViewMappedBy()->getId()); self::assertCount(1, $viewReference->getReferenceManyView()); - self::assertInstanceOf(InternalProxy::class, $viewReference->getReferenceManyView()[0]); + self::assertIsLazyObject($viewReference->getReferenceManyView()[0]); self::assertSame($malarzm->getId(), $viewReference->getReferenceManyView()[0]->getId()); // No proxies for inverse referenceMany diff --git a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php index 560e6e391..e36022545 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php @@ -10,7 +10,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Query\Query; class HydratorTest extends BaseTestCase @@ -41,10 +40,10 @@ public function testHydrator(): void self::assertEquals('jon', $user->name); self::assertInstanceOf(DateTime::class, $user->birthdate); self::assertInstanceOf(HydrationClosureReferenceOne::class, $user->referenceOne); - self::assertInstanceOf(InternalProxy::class, $user->referenceOne); + self::assertIsLazyObject($user->referenceOne); self::assertInstanceOf(PersistentCollection::class, $user->referenceMany); - self::assertInstanceOf(InternalProxy::class, $user->referenceMany[0]); - self::assertInstanceOf(InternalProxy::class, $user->referenceMany[1]); + self::assertIsLazyObject($user->referenceMany[0]); + self::assertIsLazyObject($user->referenceMany[1]); self::assertInstanceOf(HydrationClosureEmbedOne::class, $user->embedOne); self::assertInstanceOf(PersistentCollection::class, $user->embedMany); self::assertEquals('jon', $user->embedOne->name); @@ -54,7 +53,7 @@ public function testHydrator(): void public function testHydrateProxyWithMissingAssociations(): void { $user = $this->dm->getReference(HydrationClosureUser::class, 1); - self::assertInstanceOf(InternalProxy::class, $user); + self::assertIsLazyObject($user); $this->dm->getHydratorFactory()->hydrate($user, [ '_id' => 1, diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php index 5a4302abd..08d54136f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php @@ -10,7 +10,6 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; use Doctrine\ODM\MongoDB\Mapping\TimeSeries\Granularity; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; use Doctrine\ODM\MongoDB\Tests\ClassMetadataTestUtil; @@ -496,7 +495,7 @@ public function testGetFieldValueInitializesProxy(): void $metadata = $this->dm->getClassMetadata(Album::class); self::assertEquals($document->getName(), $metadata->getFieldValue($proxy, 'name')); - self::assertInstanceOf(InternalProxy::class, $proxy); + self::assertIsLazyObject($proxy); self::assertFalse($this->uow->isUninitializedObject($proxy)); } @@ -511,7 +510,7 @@ public function testGetFieldValueOfIdentifierDoesNotInitializeProxy(): void $metadata = $this->dm->getClassMetadata(Album::class); self::assertEquals($document->getId(), $metadata->getFieldValue($proxy, 'id')); - self::assertInstanceOf(InternalProxy::class, $proxy); + self::assertIsLazyObject($proxy); self::assertTrue($this->uow->isUninitializedObject($proxy)); } @@ -533,7 +532,7 @@ public function testSetFieldValueWithProxy(): void $this->dm->clear(); $proxy = $this->dm->getReference(Album::class, $document->getId()); - self::assertInstanceOf(InternalProxy::class, $proxy); + self::assertIsLazyObject($proxy); $metadata = $this->dm->getClassMetadata(Album::class); $metadata->setFieldValue($proxy, 'name', 'nevermind'); @@ -542,7 +541,7 @@ public function testSetFieldValueWithProxy(): void $this->dm->clear(); $proxy = $this->dm->getReference(Album::class, $document->getId()); - self::assertInstanceOf(InternalProxy::class, $proxy); + self::assertIsLazyObject($proxy); self::assertInstanceOf(Album::class, $proxy); self::assertEquals('nevermind', $proxy->getName()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/StaticProxyFactoryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/ProxyFactoryTest.php similarity index 98% rename from tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/StaticProxyFactoryTest.php rename to tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/ProxyFactoryTest.php index ec399b493..e62ca695e 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/StaticProxyFactoryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Proxy/Factory/ProxyFactoryTest.php @@ -16,7 +16,7 @@ use MongoDB\Database; use PHPUnit\Framework\MockObject\MockObject; -class StaticProxyFactoryTest extends BaseTestCase +class ProxyFactoryTest extends BaseTestCase { /** @var Client|MockObject */ private Client $client; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index 793476b2b..45d3b2adc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -11,7 +11,6 @@ use Doctrine\ODM\MongoDB\APM\CommandLogger; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\MongoDBException; -use Doctrine\ODM\MongoDB\Proxy\InternalProxy; use Doctrine\ODM\MongoDB\Tests\Mocks\ExceptionThrowingListenerMock; use Doctrine\ODM\MongoDB\Tests\Mocks\PreUpdateListenerMock; use Doctrine\ODM\MongoDB\UnitOfWork; @@ -489,7 +488,7 @@ public function testRecomputeChangesetForUninitializedProxyDoesNotCreateChangese $user = $this->dm->find(ForumUser::class, $id); self::assertInstanceOf(ForumUser::class, $user); - self::assertInstanceOf(InternalProxy::class, $user->getAvatar()); + self::assertIsLazyObject($user->getAvatar()); $classMetadata = $this->dm->getClassMetadata(ForumAvatar::class);