diff --git a/src/Configuration.php b/src/Configuration.php index 15b3703b6..f9b858bc6 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -337,6 +337,10 @@ public function getProxyDir(): ?string */ public function getAutoGenerateProxyClasses(): int { + if ($this->nativeLazyObject) { + return self::AUTOGENERATE_NEVER; + } + return $this->attributes['autoGenerateProxyClasses'] ?? self::AUTOGENERATE_FILE_NOT_EXISTS; } @@ -708,7 +712,7 @@ public function setUseLazyGhostObject(bool $flag): void public function isLazyGhostObjectEnabled(): bool { - return $this->lazyGhostObject; + return $this->lazyGhostObject && ! $this->nativeLazyObject; } public function setUseNativeLazyObject(bool $nativeLazyObject): void @@ -718,7 +722,6 @@ public function setUseNativeLazyObject(bool $nativeLazyObject): void } $this->nativeLazyObject = $nativeLazyObject; - $this->lazyGhostObject = ! $nativeLazyObject || $this->lazyGhostObject; } public function isNativeLazyObjectEnabled(): bool diff --git a/tests/Tests/ConfigurationTest.php b/tests/Tests/ConfigurationTest.php index c07d62c8f..e22f80c3c 100644 --- a/tests/Tests/ConfigurationTest.php +++ b/tests/Tests/ConfigurationTest.php @@ -31,6 +31,20 @@ public function testUseNativeLazyObjectBeforePHP84(): void $c->setUseNativeLazyObject(true); } + #[RequiresPhp('>= 8.4')] + public function testUseNativeLazyObjectPriorityOverLazyGhost(): void + { + $c = new Configuration(); + + $c->setUseLazyGhostObject(true); + $c->setUseNativeLazyObject(true); + + self::assertTrue($c->isNativeLazyObjectEnabled()); + self::assertFalse($c->isLazyGhostObjectEnabled()); + + self::assertSame(Configuration::AUTOGENERATE_NEVER, $c->getAutoGenerateProxyClasses()); + } + public function testUseLazyGhostObject(): void { $c = new Configuration(); @@ -42,7 +56,7 @@ public function testUseLazyGhostObject(): void self::assertFalse($c->isLazyGhostObjectEnabled()); } - public function testNativeLazyObjectDeprecatedByDefault(): void + public function testNativeLazyObjectDisabledByDefault(): void { $c = new Configuration();