Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / nikic / php-parser / test / PhpParser / BuilderFactoryTest.php
index 465f600f5b286cdc8f13fae8dc2cd7e4724b011f..9dd20a109dfca6c9ce511e3952685d2663e57d30 100644 (file)
@@ -25,15 +25,17 @@ class BuilderFactoryTest extends TestCase
 
     public function provideTestFactory() {
         return [
-            ['namespace', Builder\Namespace_::class],
-            ['class',     Builder\Class_::class],
-            ['interface', Builder\Interface_::class],
-            ['trait',     Builder\Trait_::class],
-            ['method',    Builder\Method::class],
-            ['function',  Builder\Function_::class],
-            ['property',  Builder\Property::class],
-            ['param',     Builder\Param::class],
-            ['use',       Builder\Use_::class],
+            ['namespace',   Builder\Namespace_::class],
+            ['class',       Builder\Class_::class],
+            ['interface',   Builder\Interface_::class],
+            ['trait',       Builder\Trait_::class],
+            ['method',      Builder\Method::class],
+            ['function',    Builder\Function_::class],
+            ['property',    Builder\Property::class],
+            ['param',       Builder\Param::class],
+            ['use',         Builder\Use_::class],
+            ['useFunction', Builder\Use_::class],
+            ['useConst',    Builder\Use_::class],
         ];
     }
 
@@ -67,19 +69,15 @@ class BuilderFactoryTest extends TestCase
         );
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Expected at least two expressions
-     */
     public function testConcatOneError() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Expected at least two expressions');
         (new BuilderFactory())->concat("a");
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Expected string or Expr
-     */
     public function testConcatInvalidExpr() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Expected string or Expr');
         (new BuilderFactory())->concat("a", 42);
     }
 
@@ -188,47 +186,85 @@ class BuilderFactoryTest extends TestCase
         );
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Expected string or instance of Node\Identifier
-     */
+    public function testVar() {
+        $factory = new BuilderFactory();
+        $this->assertEquals(
+            new Expr\Variable("foo"),
+            $factory->var("foo")
+        );
+        $this->assertEquals(
+            new Expr\Variable(new Expr\Variable("foo")),
+            $factory->var($factory->var("foo"))
+        );
+    }
+
+    public function testPropertyFetch() {
+        $f = new BuilderFactory();
+        $this->assertEquals(
+            new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'),
+            $f->propertyFetch($f->var('foo'), 'bar')
+        );
+        $this->assertEquals(
+            new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'),
+            $f->propertyFetch($f->var('foo'), new Identifier('bar'))
+        );
+        $this->assertEquals(
+            new Expr\PropertyFetch(new Expr\Variable('foo'), new Expr\Variable('bar')),
+            $f->propertyFetch($f->var('foo'), $f->var('bar'))
+        );
+    }
+
     public function testInvalidIdentifier() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Expected string or instance of Node\Identifier');
         (new BuilderFactory())->classConstFetch('Foo', new Expr\Variable('foo'));
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Expected string or instance of Node\Identifier or Node\Expr
-     */
     public function testInvalidIdentifierOrExpr() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Expected string or instance of Node\Identifier or Node\Expr');
         (new BuilderFactory())->staticCall('Foo', new Name('bar'));
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Name must be a string or an instance of Node\Name or Node\Expr
-     */
     public function testInvalidNameOrExpr() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr');
         (new BuilderFactory())->funcCall(new Node\Stmt\Return_());
     }
 
+    public function testInvalidVar() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Variable name must be string or Expr');
+        (new BuilderFactory())->var(new Node\Stmt\Return_());
+    }
+
     public function testIntegration() {
         $factory = new BuilderFactory;
         $node = $factory->namespace('Name\Space')
             ->addStmt($factory->use('Foo\Bar\SomeOtherClass'))
             ->addStmt($factory->use('Foo\Bar')->as('A'))
+            ->addStmt($factory->useFunction('strlen'))
+            ->addStmt($factory->useConst('PHP_VERSION'))
             ->addStmt($factory
                 ->class('SomeClass')
                 ->extend('SomeOtherClass')
                 ->implement('A\Few', '\Interfaces')
                 ->makeAbstract()
 
+                ->addStmt($factory->useTrait('FirstTrait'))
+
+                ->addStmt($factory->useTrait('SecondTrait', 'ThirdTrait')
+                    ->and('AnotherTrait')
+                    ->with($factory->traitUseAdaptation('foo')->as('bar'))
+                    ->with($factory->traitUseAdaptation('AnotherTrait', 'baz')->as('test'))
+                    ->with($factory->traitUseAdaptation('AnotherTrait', 'func')->insteadof('SecondTrait')))
+
                 ->addStmt($factory->method('firstMethod'))
 
                 ->addStmt($factory->method('someMethod')
                     ->makePublic()
                     ->makeAbstract()
-                    ->addParam($factory->param('someParam')->setTypeHint('SomeClass'))
+                    ->addParam($factory->param('someParam')->setType('SomeClass'))
                     ->setDocComment('/**
                                       * This method does something.
                                       *
@@ -254,8 +290,16 @@ namespace Name\Space;
 
 use Foo\Bar\SomeOtherClass;
 use Foo\Bar as A;
+use function strlen;
+use const PHP_VERSION;
 abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces
 {
+    use FirstTrait;
+    use SecondTrait, ThirdTrait, AnotherTrait {
+        foo as bar;
+        AnotherTrait::baz as test;
+        AnotherTrait::func insteadof SecondTrait;
+    }
     protected $someProperty;
     private $anotherProperty = array(1, 2, 3);
     function firstMethod()