AutoloaderTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace PhpParser;
  3. use PhpParser\Node\Expr;
  4. use PhpParser\Node\Scalar;
  5. /* The autoloader is already active at this point, so we only check effects here. */
  6. class AutoloaderTest extends \PHPUnit_Framework_TestCase {
  7. public function testLegacyNames() {
  8. $lexer = new \PHPParser_Lexer;
  9. $parser = new \PHPParser_Parser($lexer);
  10. $prettyPrinter = new \PHPParser_PrettyPrinter_Default;
  11. $this->assertInstanceof('PhpParser\Lexer', $lexer);
  12. $this->assertInstanceof('PhpParser\Parser', $parser);
  13. $this->assertInstanceof('PhpParser\PrettyPrinter\Standard', $prettyPrinter);
  14. }
  15. public function testPhp7ReservedNames() {
  16. if (version_compare(PHP_VERSION, '7.0-dev', '>=')) {
  17. $this->markTestSkipped('Cannot create aliases to reserved names on PHP 7');
  18. }
  19. $this->assertTrue(new Expr\Cast\Bool_(new Expr\Variable('foo')) instanceof Expr\Cast\Bool);
  20. $this->assertTrue(new Expr\Cast\Int_(new Expr\Variable('foo')) instanceof Expr\Cast\Int);
  21. $this->assertInstanceof('PhpParser\Node\Expr\Cast\Object_', new Expr\Cast\Object(new Expr\Variable('foo')));
  22. $this->assertInstanceof('PhpParser\Node\Expr\Cast\String_', new Expr\Cast\String(new Expr\Variable('foo')));
  23. $this->assertInstanceof('PhpParser\Node\Scalar\String_', new Scalar\String('foobar'));
  24. }
  25. public function testClassExists() {
  26. $this->assertTrue(class_exists('PhpParser\NodeVisitorAbstract'));
  27. $this->assertTrue(class_exists('PHPParser_NodeVisitor_NameResolver'));
  28. $this->assertFalse(class_exists('PhpParser\FooBar'));
  29. $this->assertFalse(class_exists('PHPParser_FooBar'));
  30. }
  31. }