|
33 | 33 | use ProxyManagerTestAsset\ClassWithReadOnlyProperties;
|
34 | 34 | use ProxyManagerTestAsset\ClassWithSelfHint;
|
35 | 35 | use ProxyManagerTestAsset\EmptyClass;
|
| 36 | +use ProxyManagerTestAsset\NeverCounter; |
36 | 37 | use ProxyManagerTestAsset\OtherObjectAccessClass;
|
37 | 38 | use ProxyManagerTestAsset\VoidCounter;
|
38 | 39 | use ReflectionClass;
|
39 | 40 | use ReflectionProperty;
|
| 41 | +use RuntimeException; |
40 | 42 | use stdClass;
|
41 | 43 |
|
42 | 44 | use function array_key_exists;
|
@@ -1586,6 +1588,45 @@ static function (
|
1586 | 1588 | self::assertSame($initialCounter + $increment, $proxy->counter);
|
1587 | 1589 | }
|
1588 | 1590 |
|
| 1591 | + /** |
| 1592 | + * @requires PHP 8.1 |
| 1593 | + * |
| 1594 | + * @psalm-suppress UnusedVariable this method uses by-ref assignment of properties, and isn't recognized by static analysis |
| 1595 | + * @psalm-suppress UndefinedClass Class, interface or enum named never does not exist |
| 1596 | + */ |
| 1597 | + public function testWillExecuteLogicInANeverMethod(): void |
| 1598 | + { |
| 1599 | + $initialCounter = random_int(10, 1000); |
| 1600 | + |
| 1601 | + $proxy = (new LazyLoadingGhostFactory())->createProxy( |
| 1602 | + NeverCounter::class, |
| 1603 | + static function ( |
| 1604 | + LazyLoadingInterface $proxy, |
| 1605 | + string $method, |
| 1606 | + array $params, |
| 1607 | + ?Closure & $initializer, |
| 1608 | + array $properties |
| 1609 | + ) use ($initialCounter): bool { |
| 1610 | + $initializer = null; |
| 1611 | + |
| 1612 | + $properties['counter'] = $initialCounter; |
| 1613 | + |
| 1614 | + return true; |
| 1615 | + } |
| 1616 | + ); |
| 1617 | + |
| 1618 | + $increment = random_int(1001, 10000); |
| 1619 | + |
| 1620 | + try { |
| 1621 | + $proxy->increment($increment); |
| 1622 | + $this->fail('RuntimeException expected'); |
| 1623 | + } catch (RuntimeException $e) { |
| 1624 | + // Nothing to do |
| 1625 | + } |
| 1626 | + |
| 1627 | + self::assertSame($initialCounter + $increment, $proxy->counter); |
| 1628 | + } |
| 1629 | + |
1589 | 1630 | private static function isPropertyInitialized($object, ReflectionProperty $property): bool
|
1590 | 1631 | {
|
1591 | 1632 | return array_key_exists(
|
|
0 commit comments