diff vendor/nikic/php-parser/test/PhpParser/Builder/TraitTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 5fb285c0d0e3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/nikic/php-parser/test/PhpParser/Builder/TraitTest.php	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,48 @@
+<?php
+
+namespace PhpParser\Builder;
+
+use PhpParser\Comment;
+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');
+        $prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, array(
+            new Stmt\PropertyProperty('test')
+        ));
+        $use = new Stmt\TraitUse([new Name('OtherTrait')]);
+        $trait = $this->createTraitBuilder('TestTrait')
+            ->setDocComment('/** Nice trait */')
+            ->addStmt($method1)
+            ->addStmts([$method2, $method3])
+            ->addStmt($prop)
+            ->addStmt($use)
+            ->getNode();
+        $this->assertEquals(new Stmt\Trait_('TestTrait', [
+            'stmts' => [$use, $prop, $method1, $method2, $method3]
+        ], [
+            'comments' => [
+                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()))
+        ;
+    }
+}