1<?php declare(strict_types=1); 2 3namespace PhpParser\Node\Expr; 4 5use PhpParser\Node\Arg; 6use PhpParser\Node\Name; 7use PhpParser\Node\Scalar\Int_; 8use PhpParser\Node\VariadicPlaceholder; 9 10class CallableLikeTest extends \PHPUnit\Framework\TestCase { 11 /** 12 * @dataProvider provideTestIsFirstClassCallable 13 */ 14 public function testIsFirstClassCallable(CallLike $node, bool $isFirstClassCallable): void { 15 $this->assertSame($isFirstClassCallable, $node->isFirstClassCallable()); 16 if (!$isFirstClassCallable) { 17 $this->assertSame($node->getRawArgs(), $node->getArgs()); 18 } 19 } 20 21 public static function provideTestIsFirstClassCallable() { 22 $normalArgs = [new Arg(new Int_(1))]; 23 $callableArgs = [new VariadicPlaceholder()]; 24 return [ 25 [new FuncCall(new Name('test'), $normalArgs), false], 26 [new FuncCall(new Name('test'), $callableArgs), true], 27 [new MethodCall(new Variable('this'), 'test', $normalArgs), false], 28 [new MethodCall(new Variable('this'), 'test', $callableArgs), true], 29 [new StaticCall(new Name('Test'), 'test', $normalArgs), false], 30 [new StaticCall(new Name('Test'), 'test', $callableArgs), true], 31 [new New_(new Name('Test'), $normalArgs), false], 32 [new NullsafeMethodCall(new Variable('this'), 'test', $normalArgs), false], 33 // This is not legal code, but accepted by the parser. 34 [new New_(new Name('Test'), $callableArgs), true], 35 [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), true], 36 ]; 37 } 38} 39