|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace ProxyManagerTest\ProxyGenerator\Functional; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator; |
| 9 | +use ProxyManagerTestAsset\ClassWithMixedProperties; |
| 10 | + |
| 11 | +use function sprintf; |
| 12 | + |
| 13 | +/** |
| 14 | + * @covers \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator |
| 15 | + * @coversNothing |
| 16 | + */ |
| 17 | +final class PublicScopeSimulatorFunctionalTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @group #632 |
| 21 | + * @group #645 |
| 22 | + * @group #646 |
| 23 | + */ |
| 24 | + public function testAccessingUndefinedPropertiesDoesNotLeadToInvalidByRefAccess(): void |
| 25 | + { |
| 26 | + /** @psalm-var ClassWithMixedProperties $sut */ |
| 27 | + $sut = eval(sprintf( |
| 28 | +<<<'PHP' |
| 29 | +return new class() extends %s { |
| 30 | + public function doGet($prop) : string { %s } |
| 31 | + public function doSet($prop, $val) : string { %s } |
| 32 | + public function doIsset($prop) : bool { %s } |
| 33 | + public function doUnset($prop) : void { %s } |
| 34 | +}; |
| 35 | +PHP |
| 36 | + , |
| 37 | + ClassWithMixedProperties::class, |
| 38 | + PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_GET, 'prop'), |
| 39 | + PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_SET, 'prop', 'val'), |
| 40 | + PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_ISSET, 'prop'), |
| 41 | + PublicScopeSimulator::getPublicAccessSimulationCode(PublicScopeSimulator::OPERATION_UNSET, 'prop') |
| 42 | + )); |
| 43 | + |
| 44 | + self::assertSame('publicProperty0', $sut->doGet('publicProperty0')); |
| 45 | + self::assertSame('bar', $sut->doSet('publicProperty0', 'bar')); |
| 46 | + self::assertTrue($sut->doIsset('publicProperty0')); |
| 47 | + self::assertNull($sut->doUnset('publicProperty0')); |
| 48 | + } |
| 49 | +} |
0 commit comments