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