diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 0510f6c47ad59..4d827d53e28b7 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -29,7 +29,6 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; -use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\LazyServiceDumper; @@ -168,15 +167,7 @@ public function dump(array $options = []): string|array if ($this->getProxyDumper() instanceof NullDumper) { (new AnalyzeServiceReferencesPass(true, false))->process($this->container); - try { - (new CheckCircularReferencesPass())->process($this->container); - } catch (ServiceCircularReferenceException $e) { - $path = $e->getPath(); - end($path); - $path[key($path)] .= '". Try running "composer require symfony/proxy-manager-bridge'; - - throw new ServiceCircularReferenceException($e->getServiceId(), $path); - } + (new CheckCircularReferencesPass())->process($this->container); } $this->analyzeReferences(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 316c89d461e37..12d5b80f8baf3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -765,7 +765,7 @@ public function testCircularReferenceAllowanceForLazyServices() $dumper = new PhpDumper($container); $dumper->setProxyDumper(new NullDumper()); - $message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".'; + $message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo".'; $this->expectException(ServiceCircularReferenceException::class); $this->expectExceptionMessage($message); diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index f79d9a2723b36..baaef5da89b33 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -31,8 +31,7 @@ "symfony/yaml": "", "symfony/config": "", "symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required", - "symfony/expression-language": "For using expressions in service container configuration", - "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them" + "symfony/expression-language": "For using expressions in service container configuration" }, "conflict": { "ext-psr": "<1.1|>=2", diff --git a/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php b/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php index c43c9fc86a66c..f2ee0d62fb9e4 100644 --- a/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php @@ -15,6 +15,7 @@ use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Uuid; use Symfony\Component\VarDumper\Cloner\Stub; +use Symfony\Component\VarExporter\Internal\LazyObjectState; /** * @final @@ -67,6 +68,22 @@ public static function castHttpClientResponse($response, array $a, Stub $stub, b return $a; } + public static function castLazyObjectState($state, array $a, Stub $stub, bool $isNested) + { + if (!$isNested) { + return $a; + } + + $stub->cut += \count($a) - 1; + + return ['status' => new ConstStub(match ($a['status']) { + LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL', + LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL', + LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL', + LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL', + }, $a['status'])]; + } + public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested) { $a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58(); diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index c722a8e905c2b..6c3efdeb60209 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -89,6 +89,7 @@ abstract class AbstractCloner implements ClonerInterface 'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'], 'Symfony\Component\Uid\Ulid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'], 'Symfony\Component\Uid\Uuid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'], + 'Symfony\Component\VarExporter\Internal\LazyObjectState' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castLazyObjectState'], 'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'], 'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'], 'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'], diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php index 3951866b57219..2ce7df11b6741 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php @@ -20,11 +20,6 @@ */ class LazyObjectRegistry { - /** - * @var array - */ - public static $states = []; - /** * @var array */ @@ -50,6 +45,11 @@ class LazyObjectRegistry */ public static $parentMethods = []; + /** + * @var LazyObjectState + */ + public static $noInitializerState; + public static function getClassResetters($class) { $classProperties = []; @@ -63,7 +63,7 @@ public static function getClassResetters($class) foreach ($propertyScopes as $key => [$scope, $name, $readonlyScope]) { $propertyScopes[$k = "\0$scope\0$name"] ?? $propertyScopes[$k = "\0*\0$name"] ?? $k = $name; - if ($k === $key && "\0$class\0lazyObjectId" !== $k) { + if ($k === $key && "\0$class\0lazyObjectState" !== $k) { $classProperties[$readonlyScope ?? $scope][$name] = $key; } } diff --git a/src/Symfony/Component/VarExporter/LazyGhostTrait.php b/src/Symfony/Component/VarExporter/LazyGhostTrait.php index df40c267fd027..21bef1cb5b495 100644 --- a/src/Symfony/Component/VarExporter/LazyGhostTrait.php +++ b/src/Symfony/Component/VarExporter/LazyGhostTrait.php @@ -17,7 +17,7 @@ trait LazyGhostTrait { - private int $lazyObjectId; + private LazyObjectState $lazyObjectState; /** * Creates a lazy-loading ghost instance. @@ -47,15 +47,14 @@ public static function createLazyGhost(\Closure|array $initializer, array $skipp $onlyProperties = null === $skippedProperties && \is_array($initializer) ? $initializer : null; if (self::class !== $class = $instance ? $instance::class : static::class) { - $skippedProperties["\0".self::class."\0lazyObjectId"] = true; + $skippedProperties["\0".self::class."\0lazyObjectState"] = true; } elseif (\defined($class.'::LAZY_OBJECT_PROPERTY_SCOPES')) { Hydrator::$propertyScopes[$class] ??= $class::LAZY_OBJECT_PROPERTY_SCOPES; } $instance ??= (Registry::$classReflectors[$class] ??= new \ReflectionClass($class))->newInstanceWithoutConstructor(); Registry::$defaultProperties[$class] ??= (array) $instance; - $instance->lazyObjectId = $id = spl_object_id($instance); - Registry::$states[$id] = new LazyObjectState($initializer, $skippedProperties ??= []); + $instance->lazyObjectState = new LazyObjectState($initializer, $skippedProperties ??= []); foreach (Registry::$classResetters[$class] ??= Registry::getClassResetters($class) as $reset) { $reset($instance, $skippedProperties, $onlyProperties); @@ -71,7 +70,7 @@ public static function createLazyGhost(\Closure|array $initializer, array $skipp */ public function isLazyObjectInitialized(bool $partial = false): bool { - if (!$state = Registry::$states[$this->lazyObjectId ?? ''] ?? null) { + if (!$state = $this->lazyObjectState ?? null) { return true; } @@ -101,7 +100,7 @@ public function isLazyObjectInitialized(bool $partial = false): bool */ public function initializeLazyObject(): static { - if (!$state = Registry::$states[$this->lazyObjectId ?? ''] ?? null) { + if (!$state = $this->lazyObjectState ?? null) { return $this; } @@ -151,7 +150,7 @@ public function initializeLazyObject(): static */ public function resetLazyObject(): bool { - if (!$state = Registry::$states[$this->lazyObjectId ?? ''] ?? null) { + if (!$state = $this->lazyObjectState ?? null) { return false; } @@ -169,7 +168,7 @@ public function &__get($name): mixed if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { $scope = Registry::getScope($propertyScopes, $class, $name); - $state = Registry::$states[$this->lazyObjectId ?? ''] ?? null; + $state = $this->lazyObjectState ?? null; if ($state && (null === $scope || isset($propertyScopes["\0$scope\0$name"])) && LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $readonlyScope ?? $scope) @@ -215,7 +214,7 @@ public function __set($name, $value): void if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); - $state = Registry::$states[$this->lazyObjectId ?? ''] ?? null; + $state = $this->lazyObjectState ?? null; if ($state && ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"]))) { if (LazyObjectState::STATUS_UNINITIALIZED_FULL === $state->status) { @@ -248,7 +247,7 @@ public function __isset($name): bool if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { $scope = Registry::getScope($propertyScopes, $class, $name); - $state = Registry::$states[$this->lazyObjectId ?? ''] ?? null; + $state = $this->lazyObjectState ?? null; if ($state && (null === $scope || isset($propertyScopes["\0$scope\0$name"])) && LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $readonlyScope ?? $scope) @@ -278,7 +277,7 @@ public function __unset($name): void if ([$class, , $readonlyScope] = $propertyScopes[$name] ?? null) { $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); - $state = Registry::$states[$this->lazyObjectId ?? ''] ?? null; + $state = $this->lazyObjectState ?? null; if ($state && ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"]))) { if (LazyObjectState::STATUS_UNINITIALIZED_FULL === $state->status) { @@ -306,8 +305,8 @@ public function __unset($name): void public function __clone(): void { - if ($state = Registry::$states[$this->lazyObjectId ?? ''] ?? null) { - Registry::$states[$this->lazyObjectId = spl_object_id($this)] = clone $state; + if ($state = $this->lazyObjectState ?? null) { + $this->lazyObjectState = clone $state; } if ((Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['clone']) { @@ -325,7 +324,7 @@ public function __serialize(): array $this->initializeLazyObject(); $properties = (array) $this; } - unset($properties["\0$class\0lazyObjectId"]); + unset($properties["\0$class\0lazyObjectState"]); if (Registry::$parentMethods[$class]['serialize'] || !Registry::$parentMethods[$class]['sleep']) { return $properties; @@ -349,26 +348,20 @@ public function __serialize(): array public function __destruct() { - $state = Registry::$states[$this->lazyObjectId ?? ''] ?? null; + $state = $this->lazyObjectState ?? null; - try { - if ($state && \in_array($state->status, [LazyObjectState::STATUS_UNINITIALIZED_FULL, LazyObjectState::STATUS_UNINITIALIZED_PARTIAL], true)) { - return; - } + if ($state && \in_array($state->status, [LazyObjectState::STATUS_UNINITIALIZED_FULL, LazyObjectState::STATUS_UNINITIALIZED_PARTIAL], true)) { + return; + } - if ((Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['destruct']) { - parent::__destruct(); - } - } finally { - if ($state) { - unset(Registry::$states[$this->lazyObjectId]); - } + if ((Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['destruct']) { + parent::__destruct(); } } private function setLazyObjectAsInitialized(bool $initialized): void { - $state = Registry::$states[$this->lazyObjectId ?? '']; + $state = $this->lazyObjectState ?? null; if ($state && !\is_array($state->initializer)) { $state->status = $initialized ? LazyObjectState::STATUS_INITIALIZED_FULL : LazyObjectState::STATUS_UNINITIALIZED_FULL; diff --git a/src/Symfony/Component/VarExporter/LazyProxyTrait.php b/src/Symfony/Component/VarExporter/LazyProxyTrait.php index 97509eb35321b..196da7d608e07 100644 --- a/src/Symfony/Component/VarExporter/LazyProxyTrait.php +++ b/src/Symfony/Component/VarExporter/LazyProxyTrait.php @@ -18,7 +18,7 @@ trait LazyProxyTrait { - private int $lazyObjectId; + private LazyObjectState $lazyObjectState; private object $lazyObjectReal; /** @@ -29,14 +29,13 @@ trait LazyProxyTrait public static function createLazyProxy(\Closure $initializer, self $instance = null): static { if (self::class !== $class = $instance ? $instance::class : static::class) { - $skippedProperties = ["\0".self::class."\0lazyObjectId" => true]; + $skippedProperties = ["\0".self::class."\0lazyObjectState" => true]; } elseif (\defined($class.'::LAZY_OBJECT_PROPERTY_SCOPES')) { Hydrator::$propertyScopes[$class] ??= $class::LAZY_OBJECT_PROPERTY_SCOPES; } $instance ??= (Registry::$classReflectors[$class] ??= new \ReflectionClass($class))->newInstanceWithoutConstructor(); - $instance->lazyObjectId = $id = spl_object_id($instance); - Registry::$states[$id] = new LazyObjectState($initializer); + $instance->lazyObjectState = new LazyObjectState($initializer); foreach (Registry::$classResetters[$class] ??= Registry::getClassResetters($class) as $reset) { $reset($instance, $skippedProperties ??= []); @@ -52,7 +51,7 @@ public static function createLazyProxy(\Closure $initializer, self $instance = n */ public function isLazyObjectInitialized(bool $partial = false): bool { - if (0 >= ($this->lazyObjectId ?? 0)) { + if (!isset($this->lazyObjectState) || Registry::$noInitializerState === $this->lazyObjectState) { return true; } @@ -76,7 +75,7 @@ public function initializeLazyObject(): parent */ public function resetLazyObject(): bool { - if (0 >= ($this->lazyObjectId ?? 0)) { + if (!isset($this->lazyObjectState) || Registry::$noInitializerState === $this->lazyObjectState) { return false; } @@ -97,10 +96,9 @@ public function &__get($name): mixed $scope = Registry::getScope($propertyScopes, $class, $name); if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) { - if (isset($this->lazyObjectId)) { + if ($state = $this->lazyObjectState ?? null) { if ('lazyObjectReal' === $name && self::class === $scope) { - $state = Registry::$states[$this->lazyObjectId] ?? null; - $this->lazyObjectReal = $state ? ($state->initializer)() : null; + $this->lazyObjectReal = ($state->initializer)(); return $this->lazyObjectReal; } @@ -155,7 +153,7 @@ public function __set($name, $value): void $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); if ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { - if (isset($this->lazyObjectId)) { + if (isset($this->lazyObjectState)) { if ('lazyObjectReal' === $name && self::class === $scope) { $this->lazyObjectReal = $value; @@ -197,9 +195,9 @@ public function __isset($name): bool $scope = Registry::getScope($propertyScopes, $class, $name); if (null === $scope || isset($propertyScopes["\0$scope\0$name"])) { - if (isset($this->lazyObjectId)) { + if (isset($this->lazyObjectState)) { if ('lazyObjectReal' === $name && self::class === $scope) { - $state = Registry::$states[$this->lazyObjectId] ?? null; + $state = $this->lazyObjectState ?? null; return null !== $this->lazyObjectReal = $state ? ($state->initializer)() : null; } @@ -237,7 +235,7 @@ public function __unset($name): void $scope = Registry::getScope($propertyScopes, $class, $name, $readonlyScope); if ($readonlyScope === $scope || isset($propertyScopes["\0$scope\0$name"])) { - if (isset($this->lazyObjectId)) { + if (isset($this->lazyObjectState)) { if ('lazyObjectReal' === $name && self::class === $scope) { unset($this->lazyObjectReal); @@ -271,7 +269,7 @@ public function __unset($name): void public function __clone(): void { - if (!isset($this->lazyObjectId)) { + if (!isset($this->lazyObjectState)) { if ((Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['clone']) { parent::__clone(); } @@ -282,8 +280,8 @@ public function __clone(): void if (\array_key_exists("\0".self::class."\0lazyObjectReal", (array) $this)) { $this->lazyObjectReal = clone $this->lazyObjectReal; } - if ($state = Registry::$states[$this->lazyObjectId] ?? null) { - Registry::$states[$this->lazyObjectId = spl_object_id($this)] = clone $state; + if ($state = $this->lazyObjectState ?? null) { + $this->lazyObjectState = clone $state; } } @@ -296,7 +294,7 @@ public function __serialize(): array } else { $properties = (array) $this; } - unset($properties["\0$class\0lazyObjectId"]); + unset($properties["\0$class\0lazyObjectState"]); if (isset($this->lazyObjectReal) || Registry::$parentMethods[$class]['serialize'] || !Registry::$parentMethods[$class]['sleep']) { return $properties; @@ -332,8 +330,7 @@ public function __unserialize(array $data): void } else { $this->lazyObjectReal = $data["\0$class\0lazyObjectReal"]; } - Registry::$states[-1] ??= new LazyObjectState(static fn () => throw new \LogicException('Lazy proxy has no initializer.')); - $this->lazyObjectId = -1; + $this->lazyObjectState = Registry::$noInitializerState ??= new LazyObjectState(static fn () => throw new \LogicException('Lazy proxy has no initializer.')); } elseif ((Registry::$parentMethods[$class] ??= Registry::getParentMethods($class))['unserialize']) { parent::__unserialize($data); } else { @@ -347,11 +344,7 @@ public function __unserialize(array $data): void public function __destruct() { - if (isset($this->lazyObjectId)) { - if (0 < $this->lazyObjectId) { - unset(Registry::$states[$this->lazyObjectId]); - } - + if (isset($this->lazyObjectState)) { return; } diff --git a/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php index 3663217435268..25673fb073ca8 100644 --- a/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php +++ b/src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php @@ -12,7 +12,7 @@ namespace Symfony\Component\VarExporter\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\VarExporter\Internal\LazyObjectRegistry; +use Symfony\Component\VarExporter\Internal\LazyObjectState; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildMagicClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildStdClass; use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildTestClass; @@ -28,7 +28,7 @@ public function testGetPublic() $ghost->__construct(); }); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); $this->assertSame(-4, $instance->public); $this->assertSame(4, $instance->publicReadonly); } @@ -50,7 +50,7 @@ public function testIssetPublic() $ghost->__construct(); }); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); $this->assertTrue(isset($instance->public)); $this->assertSame(4, $instance->publicReadonly); } @@ -61,7 +61,7 @@ public function testUnsetPublic() $ghost->__construct(); }); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); unset($instance->public); $this->assertFalse(isset($instance->public)); $this->assertSame(4, $instance->publicReadonly); @@ -73,7 +73,7 @@ public function testSetPublic() $ghost->__construct(); }); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); $instance->public = 12; $this->assertSame(12, $instance->public); $this->assertSame(4, $instance->publicReadonly); @@ -100,8 +100,8 @@ public function testClone() $clone = clone $instance; $this->assertNotSame((array) $instance, (array) $clone); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $clone)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $clone)); $clone = clone $clone; $this->assertTrue($clone->resetLazyObject()); @@ -114,12 +114,12 @@ public function testSerialize() }); $serialized = serialize($instance); - $this->assertStringNotContainsString('lazyObjectId', $serialized); + $this->assertStringNotContainsString('lazyObjectState', $serialized); $clone = unserialize($serialized); $expected = (array) $instance; - $this->assertArrayHasKey("\0".TestClass::class."\0lazyObjectId", $expected); - unset($expected["\0".TestClass::class."\0lazyObjectId"]); + $this->assertArrayHasKey("\0".TestClass::class."\0lazyObjectState", $expected); + unset($expected["\0".TestClass::class."\0lazyObjectState"]); $this->assertSame(array_keys($expected), array_keys((array) $clone)); $this->assertFalse($clone->resetLazyObject()); $this->assertTrue($clone->isLazyObjectInitialized()); @@ -156,29 +156,6 @@ public function provideMagicClass() })]; } - public function testDestruct() - { - $registryCount = \count(LazyObjectRegistry::$states); - $destructCounter = MagicClass::$destructCounter; - - $instance = ChildMagicClass::createLazyGhost(function (ChildMagicClass $instance) { - $instance->__construct(); - }); - - unset($instance); - $this->assertSame($destructCounter, MagicClass::$destructCounter); - - $instance = ChildMagicClass::createLazyGhost(function (ChildMagicClass $instance) { - $instance->__construct(); - }); - $instance->initializeLazyObject(); - unset($instance); - - $this->assertSame(1 + $destructCounter, MagicClass::$destructCounter); - - $this->assertCount($registryCount, LazyObjectRegistry::$states); - } - public function testResetLazyGhost() { $instance = ChildMagicClass::createLazyGhost(function (ChildMagicClass $instance) { @@ -244,12 +221,12 @@ public function testPartialInitialization() 'dummyProperty' => fn () => 123, ]); - $this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(["\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); $this->assertFalse($instance->isLazyObjectInitialized()); $this->assertSame(123, $instance->public); $this->assertFalse($instance->isLazyObjectInitialized()); $this->assertTrue($instance->isLazyObjectInitialized(true)); - $this->assertSame(['public', "\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance)); + $this->assertSame(['public', "\0".TestClass::class."\0lazyObjectState"], array_keys((array) $instance)); $this->assertSame(1, $counter); $instance->initializeLazyObject(); @@ -258,8 +235,8 @@ public function testPartialInitialization() $this->assertSame(6, $counter); $properties = (array) $instance; - $this->assertIsInt($properties["\0".TestClass::class."\0lazyObjectId"]); - unset($properties["\0".TestClass::class."\0lazyObjectId"]); + $this->assertInstanceOf(LazyObjectState::class, $properties["\0".TestClass::class."\0lazyObjectState"]); + unset($properties["\0".TestClass::class."\0lazyObjectState"]); $this->assertSame(array_keys((array) new ChildTestClass()), array_keys($properties)); $this->assertSame([123, 345, 456, 567, 234, 678], array_values($properties)); }