PropertyTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Modifiers;
  4. class PropertyTest extends \PHPUnit\Framework\TestCase {
  5. /**
  6. * @dataProvider provideModifiers
  7. */
  8. public function testModifiers($modifier): void {
  9. $node = new Property(
  10. constant(Modifiers::class . '::' . strtoupper($modifier)),
  11. [] // invalid
  12. );
  13. $this->assertTrue($node->{'is' . $modifier}());
  14. }
  15. public function testNoModifiers(): void {
  16. $node = new Property(0, []);
  17. $this->assertTrue($node->isPublic());
  18. $this->assertFalse($node->isProtected());
  19. $this->assertFalse($node->isPrivate());
  20. $this->assertFalse($node->isStatic());
  21. $this->assertFalse($node->isReadonly());
  22. }
  23. public function testStaticImplicitlyPublic(): void {
  24. $node = new Property(Modifiers::STATIC, []);
  25. $this->assertTrue($node->isPublic());
  26. $this->assertFalse($node->isProtected());
  27. $this->assertFalse($node->isPrivate());
  28. $this->assertTrue($node->isStatic());
  29. $this->assertFalse($node->isReadonly());
  30. }
  31. public static function provideModifiers() {
  32. return [
  33. ['public'],
  34. ['protected'],
  35. ['private'],
  36. ['static'],
  37. ['readonly'],
  38. ];
  39. }
  40. }