ClassMethodTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. class ClassMethodTest extends \PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * @dataProvider provideModifiers
  7. */
  8. public function testModifiers($modifier) {
  9. $node = new ClassMethod('foo', array(
  10. 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
  11. ));
  12. $this->assertTrue($node->{'is' . $modifier}());
  13. }
  14. public function testNoModifiers() {
  15. $node = new ClassMethod('foo', array('type' => 0));
  16. $this->assertTrue($node->isPublic());
  17. $this->assertFalse($node->isProtected());
  18. $this->assertFalse($node->isPrivate());
  19. $this->assertFalse($node->isAbstract());
  20. $this->assertFalse($node->isFinal());
  21. $this->assertFalse($node->isStatic());
  22. }
  23. public function provideModifiers() {
  24. return array(
  25. array('public'),
  26. array('protected'),
  27. array('private'),
  28. array('abstract'),
  29. array('final'),
  30. array('static'),
  31. );
  32. }
  33. /**
  34. * Checks that implicit public modifier detection for method is working
  35. *
  36. * @dataProvider implicitPublicModifiers
  37. *
  38. * @param integer $modifier Node type modifier
  39. */
  40. public function testImplicitPublic($modifier)
  41. {
  42. $node = new ClassMethod('foo', array(
  43. 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
  44. ));
  45. $this->assertTrue($node->isPublic(), 'Node should be implicitly public');
  46. }
  47. public function implicitPublicModifiers() {
  48. return array(
  49. array('abstract'),
  50. array('final'),
  51. array('static'),
  52. );
  53. }
  54. }