forked from nikic/PHP-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParamTest.php
More file actions
68 lines (58 loc) · 2.18 KB
/
ParamTest.php
File metadata and controls
68 lines (58 loc) · 2.18 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php declare(strict_types=1);
namespace PhpParser\Node;
use PhpParser\Modifiers;
use PhpParser\Node\Expr\Variable;
class ParamTest extends \PHPUnit\Framework\TestCase {
public function testNoModifiers(): void {
$node = new Param(new Variable('foo'));
$this->assertFalse($node->isPromoted());
$this->assertFalse($node->isPrivate());
$this->assertFalse($node->isProtected());
$this->assertFalse($node->isPrivate());
$this->assertFalse($node->isReadonly());
$this->assertFalse($node->isPublicSet());
$this->assertFalse($node->isProtectedSet());
$this->assertFalse($node->isPrivateSet());
}
/**
* @dataProvider provideModifiers
*/
public function testModifiers(string $modifier): void {
$node = new Param(new Variable('foo'));
$node->flags = constant(Modifiers::class . '::' . strtoupper($modifier));
$this->assertTrue($node->isPromoted());
$this->assertTrue($node->{'is' . $modifier}());
}
public static function provideModifiers() {
return [
['public'],
['protected'],
['private'],
['readonly'],
['final'],
];
}
public function testSetVisibility() {
$node = new Param(new Variable('foo'));
$node->flags = Modifiers::PRIVATE_SET;
$this->assertTrue($node->isPrivateSet());
$this->assertTrue($node->isPublic());
$node->flags = Modifiers::PROTECTED_SET;
$this->assertTrue($node->isProtectedSet());
$this->assertTrue($node->isPublic());
$node->flags = Modifiers::PUBLIC_SET;
$this->assertTrue($node->isPublicSet());
$this->assertTrue($node->isPublic());
}
public function testPromotedPropertyWithoutVisibilityModifier(): void {
$node = new Param(new Variable('foo'));
$get = new PropertyHook('get', null);
$node->hooks[] = $get;
$this->assertTrue($node->isPromoted());
$this->assertTrue($node->isPublic());
}
public function testNonPromotedPropertyIsNotPublic(): void {
$node = new Param(new Variable('foo'));
$this->assertFalse($node->isPublic());
}
}