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
|
<?php declare(strict_types=1);
namespace PhpParser\Node;
use PhpParser\Modifiers;
use PhpParser\Node\Expr\Variable;
use PHPUnit\Framework\Attributes\DataProvider;
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'],
];
}
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());
}
}
|