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 69
|
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Modifiers;
use PHPUnit\Framework\Attributes\DataProvider;
class PropertyTest extends \PHPUnit\Framework\TestCase {
#[DataProvider('provideModifiers')]
public function testModifiers($modifier): void {
$node = new Property(
constant(Modifiers::class . '::' . strtoupper($modifier)),
[] // invalid
);
$this->assertTrue($node->{'is' . $modifier}());
}
public function testNoModifiers(): void {
$node = new Property(0, []);
$this->assertTrue($node->isPublic());
$this->assertFalse($node->isProtected());
$this->assertFalse($node->isPrivate());
$this->assertFalse($node->isStatic());
$this->assertFalse($node->isReadonly());
$this->assertFalse($node->isPublicSet());
$this->assertFalse($node->isProtectedSet());
$this->assertFalse($node->isPrivateSet());
}
public function testStaticImplicitlyPublic(): void {
$node = new Property(Modifiers::STATIC, []);
$this->assertTrue($node->isPublic());
$this->assertFalse($node->isProtected());
$this->assertFalse($node->isPrivate());
$this->assertTrue($node->isStatic());
$this->assertFalse($node->isReadonly());
}
public static function provideModifiers() {
return [
['public'],
['protected'],
['private'],
['static'],
['readonly'],
];
}
public function testSetVisibility() {
$node = new Property(Modifiers::PRIVATE_SET, []);
$this->assertTrue($node->isPrivateSet());
$node = new Property(Modifiers::PROTECTED_SET, []);
$this->assertTrue($node->isProtectedSet());
$node = new Property(Modifiers::PUBLIC_SET, []);
$this->assertTrue($node->isPublicSet());
}
public function testIsFinal() {
$node = new Property(Modifiers::FINAL, []);
$this->assertTrue($node->isFinal());
}
public function testIsAbstract() {
$node = new Property(Modifiers::ABSTRACT, []);
$this->assertTrue($node->isAbstract());
}
}
|