PropertyTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PHPUnit\Framework\TestCase;
  4. class PropertyTest extends TestCase
  5. {
  6. /**
  7. * @dataProvider provideModifiers
  8. */
  9. public function testModifiers($modifier) {
  10. $node = new Property(
  11. constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)),
  12. [] // invalid
  13. );
  14. $this->assertTrue($node->{'is' . $modifier}());
  15. }
  16. public function testNoModifiers() {
  17. $node = new Property(0, []);
  18. $this->assertTrue($node->isPublic());
  19. $this->assertFalse($node->isProtected());
  20. $this->assertFalse($node->isPrivate());
  21. $this->assertFalse($node->isStatic());
  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. }
  30. public function provideModifiers() {
  31. return [
  32. ['public'],
  33. ['protected'],
  34. ['private'],
  35. ['static'],
  36. ];
  37. }
  38. }