PropertyTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. class PropertyTest extends \PHPUnit\Framework\TestCase
  4. {
  5. /**
  6. * @dataProvider provideModifiers
  7. */
  8. public function testModifiers($modifier) {
  9. $node = new Property(
  10. constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)),
  11. [] // invalid
  12. );
  13. $this->assertTrue($node->{'is' . $modifier}());
  14. }
  15. public function testNoModifiers() {
  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() {
  24. $node = new Property(Class_::MODIFIER_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 function testReadonly() {
  32. $node = new Property(Class_::MODIFIER_READONLY, []);
  33. $this->assertTrue($node->isReadonly());
  34. }
  35. public function provideModifiers() {
  36. return [
  37. ['public'],
  38. ['protected'],
  39. ['private'],
  40. ['static'],
  41. ];
  42. }
  43. }