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