2017-11-02 18:56:01 +01:00
|
|
|
<?php declare(strict_types=1);
|
2014-12-11 17:24:10 +01:00
|
|
|
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
|
2017-11-04 12:43:02 +01:00
|
|
|
use PhpParser\Comment\Doc;
|
2014-12-11 17:24:10 +01:00
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\Stmt;
|
2017-04-27 18:14:07 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2014-12-11 17:24:10 +01:00
|
|
|
|
2017-04-27 18:14:07 +02:00
|
|
|
class NamespaceTest extends TestCase
|
2014-12-11 17:24:10 +01:00
|
|
|
{
|
|
|
|
protected function createNamespaceBuilder($fqn) {
|
|
|
|
return new Namespace_($fqn);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreation() {
|
|
|
|
$stmt1 = new Stmt\Class_('SomeClass');
|
|
|
|
$stmt2 = new Stmt\Interface_('SomeInterface');
|
|
|
|
$stmt3 = new Stmt\Function_('someFunction');
|
2017-11-04 12:43:02 +01:00
|
|
|
$docComment = new Doc('/** Test */');
|
2014-12-11 17:24:10 +01:00
|
|
|
$expected = new Stmt\Namespace_(
|
2014-12-19 18:35:19 +01:00
|
|
|
new Node\Name('Name\Space'),
|
2017-11-04 12:45:04 +01:00
|
|
|
[$stmt1, $stmt2, $stmt3],
|
|
|
|
['comments' => [$docComment]]
|
2014-12-11 17:24:10 +01:00
|
|
|
);
|
|
|
|
|
2014-12-19 18:35:19 +01:00
|
|
|
$node = $this->createNamespaceBuilder('Name\Space')
|
2014-12-11 17:24:10 +01:00
|
|
|
->addStmt($stmt1)
|
2017-08-13 14:35:03 +02:00
|
|
|
->addStmts([$stmt2, $stmt3])
|
2017-11-04 12:43:02 +01:00
|
|
|
->setDocComment($docComment)
|
2014-12-11 17:24:10 +01:00
|
|
|
->getNode()
|
|
|
|
;
|
|
|
|
$this->assertEquals($expected, $node);
|
|
|
|
|
2017-08-13 14:35:03 +02:00
|
|
|
$node = $this->createNamespaceBuilder(new Node\Name(['Name', 'Space']))
|
2017-11-04 12:43:02 +01:00
|
|
|
->setDocComment($docComment)
|
2017-08-13 14:35:03 +02:00
|
|
|
->addStmts([$stmt1, $stmt2])
|
2014-12-11 17:24:10 +01:00
|
|
|
->addStmt($stmt3)
|
|
|
|
->getNode()
|
|
|
|
;
|
|
|
|
$this->assertEquals($expected, $node);
|
2015-03-10 15:28:19 +01:00
|
|
|
|
|
|
|
$node = $this->createNamespaceBuilder(null)->getNode();
|
|
|
|
$this->assertNull($node->name);
|
|
|
|
$this->assertEmpty($node->stmts);
|
2014-12-11 17:24:10 +01:00
|
|
|
}
|
|
|
|
}
|