2015-03-10 16:05:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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_([
|
2017-04-28 21:05:01 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|