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