|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Analyser; |
| 4 | + |
| 5 | +use PhpParser\Node; |
| 6 | +use PHPStan\Rules\Rule; |
| 7 | +use PHPStan\Testing\RuleTestCase; |
| 8 | +use PHPUnit\Framework\Attributes\RequiresPhp; |
| 9 | +use function array_filter; |
| 10 | +use function array_values; |
| 11 | +use function str_starts_with; |
| 12 | + |
| 13 | +/** |
| 14 | + * @extends RuleTestCase<Rule<Node>> |
| 15 | + */ |
| 16 | +class Bug15292Test extends RuleTestCase |
| 17 | +{ |
| 18 | + |
| 19 | + protected function getRule(): Rule |
| 20 | + { |
| 21 | + return new class implements Rule { |
| 22 | + |
| 23 | + public function getNodeType(): string |
| 24 | + { |
| 25 | + return Node::class; |
| 26 | + } |
| 27 | + |
| 28 | + public function processNode(Node $node, Scope $scope): array |
| 29 | + { |
| 30 | + return []; |
| 31 | + } |
| 32 | + |
| 33 | + }; |
| 34 | + } |
| 35 | + |
| 36 | + #[RequiresPhp('>= 8.1')] |
| 37 | + public function testCallableLikeValuesAreNotReflected(): void |
| 38 | + { |
| 39 | + Bug15292MethodsClassReflectionExtension::$askedMethods = []; |
| 40 | + $this->analyse([__DIR__ . '/data/bug-15292.php'], []); |
| 41 | + $this->assertSame([], $this->getAskedMethods('Bug15292\\')); |
| 42 | + } |
| 43 | + |
| 44 | + public function testCallableLikeGenericArgumentsAreNotReflected(): void |
| 45 | + { |
| 46 | + Bug15292MethodsClassReflectionExtension::$askedMethods = []; |
| 47 | + $this->analyse([__DIR__ . '/data/bug-15292-generic.php'], []); |
| 48 | + $this->assertSame([], $this->getAskedMethods('Bug15292Generic\\')); |
| 49 | + } |
| 50 | + |
| 51 | + public function testCallableIsReflected(): void |
| 52 | + { |
| 53 | + Bug15292MethodsClassReflectionExtension::$askedMethods = []; |
| 54 | + $this->analyse([__DIR__ . '/data/bug-15292-callable.php'], []); |
| 55 | + $this->assertContains('Bug15292Callable\BigContainer::callable_ident', $this->getAskedMethods('Bug15292Callable\\')); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @return list<string> |
| 60 | + */ |
| 61 | + private function getAskedMethods(string $prefix): array |
| 62 | + { |
| 63 | + return array_values(array_filter( |
| 64 | + Bug15292MethodsClassReflectionExtension::$askedMethods, |
| 65 | + static fn (string $method): bool => str_starts_with($method, $prefix), |
| 66 | + )); |
| 67 | + } |
| 68 | + |
| 69 | + public static function getAdditionalConfigFiles(): array |
| 70 | + { |
| 71 | + return [ |
| 72 | + __DIR__ . '/bug-15292.neon', |
| 73 | + ]; |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments