1<?php declare(strict_types=1);
2
3namespace PhpParser\Builder;
4
5use PhpParser\Builder;
6use PhpParser\Node\Name;
7use PhpParser\Node\Stmt;
8
9class UseTest extends \PHPUnit\Framework\TestCase {
10    protected function createUseBuilder($name, $type = Stmt\Use_::TYPE_NORMAL) {
11        return new Builder\Use_($name, $type);
12    }
13
14    public function testCreation(): void {
15        $node = $this->createUseBuilder('Foo\Bar')->getNode();
16        $this->assertEquals(new Stmt\Use_([
17            new \PhpParser\Node\UseItem(new Name('Foo\Bar'), null)
18        ]), $node);
19
20        $node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode();
21        $this->assertEquals(new Stmt\Use_([
22            new \PhpParser\Node\UseItem(new Name('Foo\Bar'), 'XYZ')
23        ]), $node);
24
25        $node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode();
26        $this->assertEquals(new Stmt\Use_([
27            new \PhpParser\Node\UseItem(new Name('foo\bar'), 'foo')
28        ], Stmt\Use_::TYPE_FUNCTION), $node);
29
30        $node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode();
31        $this->assertEquals(new Stmt\Use_([
32            new \PhpParser\Node\UseItem(new Name('foo\BAR'), 'FOO')
33        ], Stmt\Use_::TYPE_CONSTANT), $node);
34    }
35}
36