1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-11 17:09:41 +01:00
PHP-Parser/test/PhpParser/Builder/UseTest.php

31 lines
985 B
PHP
Raw Normal View History

<?php declare(strict_types=1);
2015-03-10 16:05:55 +01:00
use PhpParser\Builder;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
2017-04-27 18:14:07 +02:00
use PHPUnit\Framework\TestCase;
2015-03-10 16:05:55 +01:00
2017-04-27 18:14:07 +02:00
class UseTest extends TestCase
2015-03-10 16:05:55 +01:00
{
protected function createUseBuilder($name, $type = Stmt\Use_::TYPE_NORMAL) {
return new Builder\Use_($name, $type);
}
public function testCreation() {
$node = $this->createUseBuilder('Foo\Bar')->getNode();
2017-08-13 14:35:03 +02:00
$this->assertEquals(new Stmt\Use_([
new Stmt\UseUse(new Name('Foo\Bar'), null)
2017-08-13 14:35:03 +02:00
]), $node);
2015-03-10 16:05:55 +01:00
$node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode();
2017-08-13 14:35:03 +02:00
$this->assertEquals(new Stmt\Use_([
2015-03-10 16:05:55 +01:00
new Stmt\UseUse(new Name('Foo\Bar'), 'XYZ')
2017-08-13 14:35:03 +02:00
]), $node);
2015-03-10 16:05:55 +01:00
$node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode();
2017-08-13 14:35:03 +02:00
$this->assertEquals(new Stmt\Use_([
2015-03-10 16:05:55 +01:00
new Stmt\UseUse(new Name('foo\bar'), 'foo')
2017-08-13 14:35:03 +02:00
], Stmt\Use_::TYPE_FUNCTION), $node);
2015-03-10 16:05:55 +01:00
}
}