UseTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use PhpParser\Builder;
  3. use PhpParser\Node\Name;
  4. use PhpParser\Node\Stmt;
  5. class UseTest extends \PHPUnit_Framework_TestCase
  6. {
  7. protected function createUseBuilder($name, $type = Stmt\Use_::TYPE_NORMAL) {
  8. return new Builder\Use_($name, $type);
  9. }
  10. public function testCreation() {
  11. $node = $this->createUseBuilder('Foo\Bar')->getNode();
  12. $this->assertEquals(new Stmt\Use_(array(
  13. new Stmt\UseUse(new Name('Foo\Bar'), 'Bar')
  14. )), $node);
  15. $node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode();
  16. $this->assertEquals(new Stmt\Use_(array(
  17. new Stmt\UseUse(new Name('Foo\Bar'), 'XYZ')
  18. )), $node);
  19. $node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode();
  20. $this->assertEquals(new Stmt\Use_(array(
  21. new Stmt\UseUse(new Name('foo\bar'), 'foo')
  22. ), Stmt\Use_::TYPE_FUNCTION), $node);
  23. }
  24. public function testNonExistingMethod() {
  25. $this->setExpectedException('LogicException', 'Method "foo" does not exist');
  26. $builder = $this->createUseBuilder('Test');
  27. $builder->foo();
  28. }
  29. }