File: CallableLikeTest.php

package info (click to toggle)
php-parser 4.15.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,780 kB
  • sloc: php: 22,049; yacc: 2,050; makefile: 29; sh: 5
file content (38 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php declare(strict_types=1);

namespace PhpParser\Node\Expr;

use PhpParser\Node\Arg;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\VariadicPlaceholder;

class CallableLikeTest extends \PHPUnit\Framework\TestCase {
    /**
     * @dataProvider provideTestIsFirstClassCallable
     */
    public function testIsFirstClassCallable(CallLike $node, bool $isFirstClassCallable) {
        $this->assertSame($isFirstClassCallable, $node->isFirstClassCallable());
        if (!$isFirstClassCallable) {
            $this->assertSame($node->getRawArgs(), $node->getArgs());
        }
    }

    public function provideTestIsFirstClassCallable() {
        $normalArgs = [new Arg(new LNumber(1))];
        $callableArgs = [new VariadicPlaceholder()];
        return [
            [new FuncCall(new Name('test'), $normalArgs), false],
            [new FuncCall(new Name('test'), $callableArgs), true],
            [new MethodCall(new Variable('this'), 'test', $normalArgs), false],
            [new MethodCall(new Variable('this'), 'test', $callableArgs), true],
            [new StaticCall(new Name('Test'), 'test', $normalArgs), false],
            [new StaticCall(new Name('Test'), 'test', $callableArgs), true],
            [new New_(new Name('Test'), $normalArgs), false],
            [new NullsafeMethodCall(new Variable('this'), 'test', $normalArgs), false],
            // This is not legal code, but accepted by the parser.
            [new New_(new Name('Test'), $callableArgs), true],
            [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), true],
        ];
    }
}