CompatibilityTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php declare(strict_types=1);
  2. namespace PhpParser;
  3. use PhpParser\Node\Expr;
  4. use PhpParser\Node\InterpolatedStringPart;
  5. use PhpParser\Node\Name;
  6. use PhpParser\Node\Scalar;
  7. use PhpParser\Node\Stmt;
  8. class CompatibilityTest extends \PHPUnit\Framework\TestCase {
  9. /**
  10. * @runInSeparateProcess
  11. * @preserveGlobalState disabled
  12. */
  13. public function testAliases1(): void {
  14. $var = new Expr\Variable('x');
  15. $node = new Node\ClosureUse($var);
  16. $this->assertTrue($node instanceof Expr\ClosureUse);
  17. $node = new Node\ArrayItem($var);
  18. $this->assertTrue($node instanceof Expr\ArrayItem);
  19. $node = new Node\StaticVar($var);
  20. $this->assertTrue($node instanceof Stmt\StaticVar);
  21. $node = new Scalar\Float_(1.0);
  22. $this->assertTrue($node instanceof Scalar\DNumber);
  23. $node = new Scalar\Int_(1);
  24. $this->assertTrue($node instanceof Scalar\LNumber);
  25. $part = new InterpolatedStringPart('foo');
  26. $this->assertTrue($part instanceof Scalar\EncapsedStringPart);
  27. $node = new Scalar\InterpolatedString([$part]);
  28. $this->assertTrue($node instanceof Scalar\Encapsed);
  29. $node = new Node\DeclareItem('strict_types', new Scalar\Int_(1));
  30. $this->assertTrue($node instanceof Stmt\DeclareDeclare);
  31. $node = new Node\PropertyItem('x');
  32. $this->assertTrue($node instanceof Stmt\PropertyProperty);
  33. $node = new Node\UseItem(new Name('X'));
  34. $this->assertTrue($node instanceof Stmt\UseUse);
  35. }
  36. /**
  37. * @runInSeparateProcess
  38. * @preserveGlobalState disabled
  39. */
  40. public function testAliases2(): void {
  41. $var = new Expr\Variable('x');
  42. $node = new Node\Expr\ClosureUse($var);
  43. $this->assertTrue($node instanceof Node\ClosureUse);
  44. $node = new Node\Expr\ArrayItem($var);
  45. $this->assertTrue($node instanceof Node\ArrayItem);
  46. $node = new Node\Stmt\StaticVar($var);
  47. $this->assertTrue($node instanceof Node\StaticVar);
  48. $node = new Node\Scalar\DNumber(1.0);
  49. $this->assertTrue($node instanceof Scalar\Float_);
  50. $node = new Node\Scalar\LNumber(1);
  51. $this->assertTrue($node instanceof Scalar\Int_);
  52. $part = new Node\Scalar\EncapsedStringPart('foo');
  53. $this->assertTrue($part instanceof Node\InterpolatedStringPart);
  54. $node = new Scalar\Encapsed([$part]);
  55. $this->assertTrue($node instanceof Scalar\InterpolatedString);
  56. $node = new Stmt\DeclareDeclare('strict_types', new Scalar\LNumber(1));
  57. $this->assertTrue($node instanceof Node\DeclareItem);
  58. $node = new Stmt\PropertyProperty('x');
  59. $this->assertTrue($node instanceof Node\PropertyItem);
  60. $node = new Stmt\UseUse(new Name('X'));
  61. $this->assertTrue($node instanceof Node\UseItem);
  62. }
  63. }