InterfaceTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Node\Scalar\String_;
  5. class InterfaceTest extends \PHPUnit\Framework\TestCase {
  6. public function testGetMethods(): void {
  7. $methods = [
  8. new ClassMethod('foo'),
  9. new ClassMethod('bar'),
  10. ];
  11. $interface = new Interface_('Foo', [
  12. 'stmts' => [
  13. new Node\Stmt\ClassConst([new Node\Const_('C1', new Node\Scalar\String_('C1'))]),
  14. $methods[0],
  15. new Node\Stmt\ClassConst([new Node\Const_('C2', new Node\Scalar\String_('C2'))]),
  16. $methods[1],
  17. new Node\Stmt\ClassConst([new Node\Const_('C3', new Node\Scalar\String_('C3'))]),
  18. ]
  19. ]);
  20. $this->assertSame($methods, $interface->getMethods());
  21. }
  22. public function testGetConstants(): void {
  23. $constants = [
  24. new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]),
  25. new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]),
  26. ];
  27. $class = new Interface_('Foo', [
  28. 'stmts' => [
  29. new TraitUse([]),
  30. $constants[0],
  31. new ClassMethod('fooBar'),
  32. $constants[1],
  33. ]
  34. ]);
  35. $this->assertSame($constants, $class->getConstants());
  36. }
  37. }