mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-11 16:49:43 +01:00
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace PhpParser\Builder;
|
||
|
|
||
|
use PhpParser\Comment;
|
||
|
use PhpParser\Node;
|
||
|
use PhpParser\Node\Name;
|
||
|
use PhpParser\Node\Stmt;
|
||
|
|
||
|
class TraitTest extends \PHPUnit_Framework_TestCase
|
||
|
{
|
||
|
protected function createTraitBuilder($class) {
|
||
|
return new Trait_($class);
|
||
|
}
|
||
|
|
||
|
public function testStmtAddition() {
|
||
|
$method1 = new Stmt\ClassMethod('test1');
|
||
|
$method2 = new Stmt\ClassMethod('test2');
|
||
|
$method3 = new Stmt\ClassMethod('test3');
|
||
|
$trait = $this->createTraitBuilder('TestTrait')
|
||
|
->setDocComment('/** Nice trait */')
|
||
|
->addStmt($method1)
|
||
|
->addStmts(array($method2, $method3))
|
||
|
->getNode();
|
||
|
$this->assertEquals(new Stmt\Trait_('TestTrait', array(
|
||
|
$method1, $method2, $method3
|
||
|
), array(
|
||
|
'comments' => array(
|
||
|
new Comment\Doc('/** Nice trait */')
|
||
|
)
|
||
|
)), $trait);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @expectedException \LogicException
|
||
|
* @expectedExceptionMessage Unexpected node of type "Stmt_Echo"
|
||
|
*/
|
||
|
public function testInvalidStmtError() {
|
||
|
$this->createTraitBuilder('Test')
|
||
|
->addStmt(new Stmt\Echo_(array()))
|
||
|
;
|
||
|
}
|
||
|
}
|