php-parser/test/PhpParser/Builder/UseTest.php

36 lines
1.2 KiB
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);
2018-07-20 21:43:43 +02:00
$node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode();
$this->assertEquals(new Stmt\Use_([
new Stmt\UseUse(new Name('foo\BAR'), 'FOO')
], Stmt\Use_::TYPE_CONSTANT), $node);
2015-03-10 16:05:55 +01:00
}
}