Chris@13: createMethodBuilder('test') Chris@0: ->makePublic() Chris@0: ->makeAbstract() Chris@0: ->makeStatic() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@0: 'flags' => Stmt\Class_::MODIFIER_PUBLIC Chris@0: | Stmt\Class_::MODIFIER_ABSTRACT Chris@0: | Stmt\Class_::MODIFIER_STATIC, Chris@0: 'stmts' => null, Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->makeProtected() Chris@0: ->makeFinal() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@0: 'flags' => Stmt\Class_::MODIFIER_PROTECTED Chris@0: | Stmt\Class_::MODIFIER_FINAL Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->makePrivate() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@0: 'type' => Stmt\Class_::MODIFIER_PRIVATE Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: Chris@0: public function testReturnByRef() { Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->makeReturnByRef() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@0: 'byRef' => true Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: Chris@0: public function testParams() { Chris@13: $param1 = new Node\Param(new Variable('test1')); Chris@13: $param2 = new Node\Param(new Variable('test2')); Chris@13: $param3 = new Node\Param(new Variable('test3')); Chris@0: Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->addParam($param1) Chris@13: ->addParams([$param2, $param3]) Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@13: 'params' => [$param1, $param2, $param3] Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: Chris@0: public function testStmts() { Chris@0: $stmt1 = new Print_(new String_('test1')); Chris@0: $stmt2 = new Print_(new String_('test2')); Chris@0: $stmt3 = new Print_(new String_('test3')); Chris@0: Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->addStmt($stmt1) Chris@13: ->addStmts([$stmt2, $stmt3]) Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@13: new Stmt\ClassMethod('test', [ Chris@13: 'stmts' => [ Chris@13: new Stmt\Expression($stmt1), Chris@13: new Stmt\Expression($stmt2), Chris@13: new Stmt\Expression($stmt3), Chris@13: ] Chris@13: ]), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: public function testDocComment() { Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->setDocComment('/** Test */') Chris@0: ->getNode(); Chris@0: Chris@13: $this->assertEquals(new Stmt\ClassMethod('test', [], [ Chris@13: 'comments' => [new Comment\Doc('/** Test */')] Chris@13: ]), $node); Chris@0: } Chris@0: Chris@0: public function testReturnType() { Chris@0: $node = $this->createMethodBuilder('test') Chris@0: ->setReturnType('bool') Chris@0: ->getNode(); Chris@13: $this->assertEquals(new Stmt\ClassMethod('test', [ Chris@0: 'returnType' => 'bool' Chris@13: ], []), $node); Chris@0: } Chris@0: Chris@0: public function testAddStmtToAbstractMethodError() { Chris@17: $this->expectException(\LogicException::class); Chris@17: $this->expectExceptionMessage('Cannot add statements to an abstract method'); Chris@0: $this->createMethodBuilder('test') Chris@0: ->makeAbstract() Chris@0: ->addStmt(new Print_(new String_('test'))) Chris@0: ; Chris@0: } Chris@0: Chris@0: public function testMakeMethodWithStmtsAbstractError() { Chris@17: $this->expectException(\LogicException::class); Chris@17: $this->expectExceptionMessage('Cannot make method with statements abstract'); Chris@0: $this->createMethodBuilder('test') Chris@0: ->addStmt(new Print_(new String_('test'))) Chris@0: ->makeAbstract() Chris@0: ; Chris@0: } Chris@0: Chris@0: public function testInvalidParamError() { Chris@17: $this->expectException(\LogicException::class); Chris@17: $this->expectExceptionMessage('Expected parameter node, got "Name"'); Chris@0: $this->createMethodBuilder('test') Chris@0: ->addParam(new Node\Name('foo')) Chris@0: ; Chris@0: } Chris@0: }