2014-12-11 17:24:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
|
|
|
|
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');
|
|
|
|
$expected = new Stmt\Namespace_(
|
2014-12-19 18:35:19 +01:00
|
|
|
new Node\Name('Name\Space'),
|
2017-08-13 14:35:03 +02:00
|
|
|
[$stmt1, $stmt2, $stmt3]
|
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])
|
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']))
|
|
|
|
->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
|
|
|
}
|
|
|
|
}
|