PropertyTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }
  22. public function testStaticImplicitlyPublic() {
  23. $node = new Property(Class_::MODIFIER_STATIC, []);
  24. $this->assertTrue($node->isPublic());
  25. $this->assertFalse($node->isProtected());
  26. $this->assertFalse($node->isPrivate());
  27. $this->assertTrue($node->isStatic());
  28. }
  29. public function provideModifiers() {
  30. return [
  31. ['public'],
  32. ['protected'],
  33. ['private'],
  34. ['static'],
  35. ];
  36. }
  37. }