1<?php declare(strict_types=1);
2
3namespace PhpParser\Node;
4
5use PhpParser\Modifiers;
6use PhpParser\Node\Expr\Variable;
7
8class ParamTest extends \PHPUnit\Framework\TestCase {
9    public function testNoModifiers(): void {
10        $node = new Param(new Variable('foo'));
11
12        $this->assertFalse($node->isPromoted());
13        $this->assertFalse($node->isPrivate());
14        $this->assertFalse($node->isProtected());
15        $this->assertFalse($node->isPrivate());
16        $this->assertFalse($node->isReadonly());
17        $this->assertFalse($node->isPublicSet());
18        $this->assertFalse($node->isProtectedSet());
19        $this->assertFalse($node->isPrivateSet());
20    }
21
22    /**
23     * @dataProvider provideModifiers
24     */
25    public function testModifiers(string $modifier): void {
26        $node = new Param(new Variable('foo'));
27        $node->flags = constant(Modifiers::class . '::' . strtoupper($modifier));
28        $this->assertTrue($node->isPromoted());
29        $this->assertTrue($node->{'is' . $modifier}());
30    }
31
32    public static function provideModifiers() {
33        return [
34            ['public'],
35            ['protected'],
36            ['private'],
37            ['readonly'],
38        ];
39    }
40
41    public function testSetVisibility() {
42        $node = new Param(new Variable('foo'));
43        $node->flags = Modifiers::PRIVATE_SET;
44        $this->assertTrue($node->isPrivateSet());
45        $node->flags = Modifiers::PROTECTED_SET;
46        $this->assertTrue($node->isProtectedSet());
47        $node->flags = Modifiers::PUBLIC_SET;
48        $this->assertTrue($node->isPublicSet());
49    }
50
51    public function testPromotedPropertyWithoutVisibilityModifier(): void {
52        $node = new Param(new Variable('foo'));
53        $get = new PropertyHook('get', null);
54        $node->hooks[] = $get;
55
56        $this->assertTrue($node->isPromoted());
57        $this->assertTrue($node->isPublic());
58    }
59
60    public function testNonPromotedPropertyIsNotPublic(): void {
61        $node = new Param(new Variable('foo'));
62        $this->assertFalse($node->isPublic());
63    }
64}
65