|
32 | 32 | use ProxyManagerTestAsset\ClassWithPublicStringTypedProperty;
|
33 | 33 | use ProxyManagerTestAsset\ClassWithSelfHint;
|
34 | 34 | use ProxyManagerTestAsset\EmptyClass;
|
| 35 | +use ProxyManagerTestAsset\NeverCounter; |
35 | 36 | use ProxyManagerTestAsset\OtherObjectAccessClass;
|
36 | 37 | use ProxyManagerTestAsset\VoidCounter;
|
37 | 38 | use ReflectionClass;
|
38 | 39 | use ReflectionProperty;
|
| 40 | +use RuntimeException; |
39 | 41 | use stdClass;
|
40 | 42 |
|
41 | 43 | use function array_key_exists;
|
@@ -1547,7 +1549,46 @@ static function (
|
1547 | 1549 | self::assertSame($initialCounter + $increment, $proxy->counter);
|
1548 | 1550 | }
|
1549 | 1551 |
|
1550 |
| - private static function isPropertyInitialized($object, ReflectionProperty $property): bool |
| 1552 | + /** |
| 1553 | + * @requires PHP 8.1 |
| 1554 | + * |
| 1555 | + * @psalm-suppress UnusedVariable this method uses by-ref assignment of properties, and isn't recognized by static analysis |
| 1556 | + * @psalm-suppress UndefinedClass Class, interface or enum named never does not exist |
| 1557 | + */ |
| 1558 | + public function testWillExecuteLogicInANeverMethod(): void |
| 1559 | + { |
| 1560 | + $initialCounter = random_int(10, 1000); |
| 1561 | + |
| 1562 | + $proxy = (new LazyLoadingGhostFactory())->createProxy( |
| 1563 | + NeverCounter::class, |
| 1564 | + static function ( |
| 1565 | + LazyLoadingInterface $proxy, |
| 1566 | + string $method, |
| 1567 | + array $params, |
| 1568 | + ?Closure & $initializer, |
| 1569 | + array $properties |
| 1570 | + ) use ($initialCounter): bool { |
| 1571 | + $initializer = null; |
| 1572 | + |
| 1573 | + $properties['counter'] = $initialCounter; |
| 1574 | + |
| 1575 | + return true; |
| 1576 | + } |
| 1577 | + ); |
| 1578 | + |
| 1579 | + $increment = random_int(1001, 10000); |
| 1580 | + |
| 1581 | + try { |
| 1582 | + $proxy->increment($increment); |
| 1583 | + $this->fail('RuntimeException expected'); |
| 1584 | + } catch (RuntimeException $e) { |
| 1585 | + // Nothing to do |
| 1586 | + } |
| 1587 | + |
| 1588 | + self::assertSame($initialCounter + $increment, $proxy->counter); |
| 1589 | + } |
| 1590 | + |
| 1591 | + private static function isPropertyInitialized(object $object, ReflectionProperty $property): bool |
1551 | 1592 | {
|
1552 | 1593 | return array_key_exists(
|
1553 | 1594 | ($property->isProtected() ? "\0*\0" : '')
|
|
0 commit comments