Skip to content

Commit dcb1863

Browse files
committed
[PHPStan 2.1.35] Add failing test where original Node not processed under VirtualNode
1 parent 0e00d4b commit dcb1863

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Expr\StaticCall;
7+
use PHPStan\Node\StaticMethodCallableNode;
8+
use PHPStan\Testing\TypeInferenceTestCase;
9+
10+
class VirtualNodeOriginalNodeCallbackTest extends TypeInferenceTestCase
11+
{
12+
public function testOriginalNodeOfVirtualNodeIsPassedToCallback(): void
13+
{
14+
$sawVirtualNode = false;
15+
$sawOriginalNode = false;
16+
17+
self::processFile(
18+
__DIR__ . '/data/virtual-node-original-node.php',
19+
static function (Node $node, Scope $scope) use (&$sawVirtualNode, &$sawOriginalNode): void {
20+
if ($node instanceof StaticMethodCallableNode) {
21+
$sawVirtualNode = true;
22+
return;
23+
}
24+
25+
if ($node instanceof StaticCall) {
26+
$sawOriginalNode = true;
27+
}
28+
},
29+
);
30+
31+
self::assertTrue($sawVirtualNode, 'Expected callback to receive StaticMethodCallableNode.');
32+
self::assertTrue($sawOriginalNode, 'Expected callback to receive original PhpParser\\Node\\Expr\\StaticCall.');
33+
}
34+
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace VirtualNodeOriginalNodeCallback;
4+
5+
final class Foo
6+
{
7+
public static function doFoo(): void
8+
{
9+
}
10+
11+
public function doFoo(): void
12+
{
13+
$cb = self::doFoo(...);
14+
$cb();
15+
}
16+
}

0 commit comments

Comments
 (0)