ClassTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. class ClassTest extends \PHPUnit\Framework\TestCase
  4. {
  5. public function testIsAbstract() {
  6. $class = new Class_('Foo', ['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', ['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 = [
  19. new ClassMethod('foo'),
  20. new ClassMethod('bar'),
  21. new ClassMethod('fooBar'),
  22. ];
  23. $class = new Class_('Foo', [
  24. 'stmts' => [
  25. new TraitUse([]),
  26. $methods[0],
  27. new ClassConst([]),
  28. $methods[1],
  29. new Property(0, []),
  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', [
  39. 'stmts' => [
  40. new ClassConst([]),
  41. $methodConstruct,
  42. new Property(0, []),
  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. }