From bcec33babf8de3485f810cf4f5657200594dec15 Mon Sep 17 00:00:00 2001 From: ludo Date: Wed, 11 Dec 2019 13:55:50 +0200 Subject: [PATCH] Use ReflectionClass to create proxied class instance inside PublicScopeSimulator --- .../ProxyGenerator/Util/PublicScopeSimulator.php | 2 +- .../ProxyGenerator/Util/PublicScopeSimulatorTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php b/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php index f87750e5d..42421bde3 100644 --- a/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php +++ b/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php @@ -112,7 +112,7 @@ private static function getTargetObject(?PropertyGenerator $valueHolder = null) return '$this->' . $valueHolder->getName(); } - return 'unserialize(sprintf(\'O:%d:"%s":0:{}\', strlen(get_parent_class($this)), get_parent_class($this)))'; + return '$realInstanceReflection->newInstanceWithoutConstructor()'; } /** diff --git a/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php b/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php index 94277c5af..cec7106e8 100644 --- a/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php +++ b/tests/ProxyManagerTest/ProxyGenerator/Util/PublicScopeSimulatorTest.php @@ -40,7 +40,7 @@ public function testSimpleGet() : void return; } -$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this))); +$targetObject = $realInstanceReflection->newInstanceWithoutConstructor(); $accessor = function & () use ($targetObject, $name) { return $targetObject->$foo; }; @@ -74,7 +74,7 @@ public function testSimpleSet() : void return; } -$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this))); +$targetObject = $realInstanceReflection->newInstanceWithoutConstructor(); $accessor = function & () use ($targetObject, $name, $value) { return $targetObject->$foo = $baz; }; @@ -108,7 +108,7 @@ public function testSimpleIsset() : void return; } -$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this))); +$targetObject = $realInstanceReflection->newInstanceWithoutConstructor(); $accessor = function () use ($targetObject, $name) { return isset($targetObject->$foo); }; @@ -142,7 +142,7 @@ public function testSimpleUnset() : void return; } -$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this))); +$targetObject = $realInstanceReflection->newInstanceWithoutConstructor(); $accessor = function () use ($targetObject, $name) { unset($targetObject->$foo); }; @@ -241,7 +241,7 @@ public function testWillReturnDirectlyWithNoReturnParam() : void return; } -$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this))); +$targetObject = $realInstanceReflection->newInstanceWithoutConstructor(); $accessor = function & () use ($targetObject, $name) { return $targetObject->$foo; };