88use Laminas \Code \Generator \PropertyGenerator ;
99use PHPUnit \Framework \TestCase ;
1010use ProxyManager \ProxyGenerator \Util \PublicScopeSimulator ;
11+ use ProxyManagerTestAsset \ClassWithMixedProperties ;
12+
13+ use function sprintf ;
1114
1215/**
1316 * Tests for {@see \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator}
@@ -41,7 +44,7 @@ public function testSimpleGet(): void
4144}
4245
4346$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
44- $accessor = function & () use ($targetObject, $name ) {
47+ $accessor = function & () use ($targetObject, $foo ) {
4548 return $targetObject->$foo;
4649};
4750$backtrace = debug_backtrace(true, 2);
@@ -70,13 +73,13 @@ public function testSimpleSet(): void
7073if (! $realInstanceReflection->hasProperty($foo)) {
7174 $targetObject = $this;
7275
73- return $targetObject->$foo = $baz;
76+ $targetObject->$foo = $baz; return $targetObject->$foo ;
7477 return;
7578}
7679
7780$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
78- $accessor = function & () use ($targetObject, $name , $value ) {
79- return $targetObject->$foo = $baz;
81+ $accessor = function & () use ($targetObject, $foo , $baz ) {
82+ $targetObject->$foo = $baz; return $targetObject->$foo ;
8083};
8184$backtrace = debug_backtrace(true, 2);
8285$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
@@ -109,7 +112,7 @@ public function testSimpleIsset(): void
109112}
110113
111114$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
112- $accessor = function () use ($targetObject, $name ) {
115+ $accessor = function () use ($targetObject, $foo ) {
113116 return isset($targetObject->$foo);
114117};
115118$backtrace = debug_backtrace(true, 2);
@@ -143,7 +146,7 @@ public function testSimpleUnset(): void
143146}
144147
145148$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
146- $accessor = function () use ($targetObject, $name ) {
149+ $accessor = function () use ($targetObject, $foo ) {
147150 unset($targetObject->$foo);
148151};
149152$backtrace = debug_backtrace(true, 2);
@@ -185,13 +188,13 @@ public function testDelegatesToValueHolderWhenAvailable(): void
185188if (! $realInstanceReflection->hasProperty($foo)) {
186189 $targetObject = $this->valueHolder;
187190
188- return $targetObject->$foo = $baz;
191+ $targetObject->$foo = $baz; return $targetObject->$foo ;
189192 return;
190193}
191194
192195$targetObject = $this->valueHolder;
193- $accessor = function & () use ($targetObject, $name , $value ) {
194- return $targetObject->$foo = $baz;
196+ $accessor = function & () use ($targetObject, $foo , $baz ) {
197+ $targetObject->$foo = $baz; return $targetObject->$foo ;
195198};
196199$backtrace = debug_backtrace(true, 2);
197200$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
@@ -242,7 +245,7 @@ public function testWillReturnDirectlyWithNoReturnParam(): void
242245}
243246
244247$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
245- $accessor = function & () use ($targetObject, $name ) {
248+ $accessor = function & () use ($targetObject, $foo ) {
246249 return $targetObject->$foo;
247250};
248251$backtrace = debug_backtrace(true, 2);
@@ -261,4 +264,30 @@ public function testWillReturnDirectlyWithNoReturnParam(): void
261264 )
262265 );
263266 }
267+
268+ public function testFunctional (): void
269+ {
270+ /** @psalm-var ClassWithMixedProperties $sut */
271+ $ sut = eval (
272+ sprintf (
273+ 'return new class() extends %s
274+ {
275+ public function doGet($prop) { %s }
276+ public function doSet($prop, $val) { %s }
277+ public function doIsset($prop) { %s }
278+ public function doUnset($prop) { %s }
279+ }; ' ,
280+ ClassWithMixedProperties::class,
281+ PublicScopeSimulator::getPublicAccessSimulationCode (PublicScopeSimulator::OPERATION_GET , 'prop ' ),
282+ PublicScopeSimulator::getPublicAccessSimulationCode (PublicScopeSimulator::OPERATION_SET , 'prop ' , 'val ' ),
283+ PublicScopeSimulator::getPublicAccessSimulationCode (PublicScopeSimulator::OPERATION_ISSET , 'prop ' ),
284+ PublicScopeSimulator::getPublicAccessSimulationCode (PublicScopeSimulator::OPERATION_UNSET , 'prop ' )
285+ )
286+ );
287+
288+ $ this ->assertSame ('publicProperty0 ' , $ sut ->doGet ('publicProperty0 ' ));
289+ $ this ->assertSame ('bar ' , $ sut ->doSet ('publicProperty0 ' , 'bar ' ));
290+ $ this ->assertTrue ($ sut ->doIsset ('publicProperty0 ' ));
291+ $ this ->assertNull ($ sut ->doUnset ('publicProperty0 ' ));
292+ }
264293}
0 commit comments