ClassTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. class ClassTest extends \PHPUnit_Framework_TestCase
  4. {
  5. public function testIsAbstract() {
  6. $class = new Class_('Foo', array('type' => Class_::MODIFIER_ABSTRACT));
  7. $this->assertTrue($class->isAbstract());
  8. $class = new Class_('Foo');
  9. $this->assertFalse($class->isAbstract());
  10. }
  11. public function testIsFinal() {
  12. $class = new Class_('Foo', array('type' => Class_::MODIFIER_FINAL));
  13. $this->assertTrue($class->isFinal());
  14. $class = new Class_('Foo');
  15. $this->assertFalse($class->isFinal());
  16. }
  17. public function testGetMethods() {
  18. $methods = array(
  19. new ClassMethod('foo'),
  20. new ClassMethod('bar'),
  21. new ClassMethod('fooBar'),
  22. );
  23. $class = new Class_('Foo', array(
  24. 'stmts' => array(
  25. new TraitUse(array()),
  26. $methods[0],
  27. new ClassConst(array()),
  28. $methods[1],
  29. new Property(0, array()),
  30. $methods[2],
  31. )
  32. ));
  33. $this->assertSame($methods, $class->getMethods());
  34. }
  35. public function testGetMethod() {
  36. $methodConstruct = new ClassMethod('__CONSTRUCT');
  37. $methodTest = new ClassMethod('test');
  38. $class = new Class_('Foo', array(
  39. 'stmts' => array(
  40. new ClassConst(array()),
  41. $methodConstruct,
  42. new Property(0, array()),
  43. $methodTest,
  44. )
  45. ));
  46. $this->assertSame($methodConstruct, $class->getMethod('__construct'));
  47. $this->assertSame($methodTest, $class->getMethod('test'));
  48. $this->assertNull($class->getMethod('nonExisting'));
  49. }
  50. public function testDeprecatedTypeNode() {
  51. $class = new Class_('Foo', array('type' => Class_::MODIFIER_ABSTRACT));
  52. $this->assertTrue($class->isAbstract());
  53. $this->assertSame(Class_::MODIFIER_ABSTRACT, $class->flags);
  54. $this->assertSame(Class_::MODIFIER_ABSTRACT, $class->type);
  55. }
  56. }