Вход Регистрация
Файл: gapps/vendor/nikic/php-parser/test/PhpParser/Builder/MethodTest.php
Строк: 109
<?php

namespace PhpParserBuilder;

use 
PhpParserNode;
use 
PhpParserNodeExprPrint_;
use 
PhpParserNodeScalarString_;
use 
PhpParserNodeStmt;
use 
PhpParserComment;

class 
MethodTest extends PHPUnit_Framework_TestCase
{
    public function 
createMethodBuilder($name) {
        return new 
Method($name);
    }

    public function 
testModifiers() {
        
$node $this->createMethodBuilder('test')
            ->
makePublic()
            ->
makeAbstract()
            ->
makeStatic()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'type' => StmtClass_::MODIFIER_PUBLIC
                        
StmtClass_::MODIFIER_ABSTRACT
                        
StmtClass_::MODIFIER_STATIC,
                
'stmts' => null,
            )),
            
$node
        
);

        
$node $this->createMethodBuilder('test')
            ->
makeProtected()
            ->
makeFinal()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'type' => StmtClass_::MODIFIER_PROTECTED
                        
StmtClass_::MODIFIER_FINAL
            
)),
            
$node
        
);

        
$node $this->createMethodBuilder('test')
            ->
makePrivate()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'type' => StmtClass_::MODIFIER_PRIVATE
            
)),
            
$node
        
);
    }

    public function 
testReturnByRef() {
        
$node $this->createMethodBuilder('test')
            ->
makeReturnByRef()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'byRef' => true
            
)),
            
$node
        
);
    }

    public function 
testParams() {
        
$param1 = new NodeParam('test1');
        
$param2 = new NodeParam('test2');
        
$param3 = new NodeParam('test3');

        
$node $this->createMethodBuilder('test')
            ->
addParam($param1)
            ->
addParams(array($param2$param3))
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'params' => array($param1$param2$param3)
            )),
            
$node
        
);
    }

    public function 
testStmts() {
        
$stmt1 = new Print_(new String_('test1'));
        
$stmt2 = new Print_(new String_('test2'));
        
$stmt3 = new Print_(new String_('test3'));

        
$node $this->createMethodBuilder('test')
            ->
addStmt($stmt1)
            ->
addStmts(array($stmt2$stmt3))
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClassMethod('test', array(
                
'stmts' => array($stmt1$stmt2$stmt3)
            )),
            
$node
        
);
    }
    public function 
testDocComment() {
        
$node $this->createMethodBuilder('test')
            ->
setDocComment('/** Test */')
            ->
getNode();

        
$this->assertEquals(new StmtClassMethod('test', array(), array(
            
'comments' => array(new CommentDoc('/** Test */'))
        )), 
$node);
    }

    public function 
testReturnType() {
        
$node $this->createMethodBuilder('test')
            ->
setReturnType('bool')
            ->
getNode();
        
$this->assertEquals(new StmtClassMethod('test', array(
            
'returnType' => 'bool'
        
), array()), $node);
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Cannot add statements to an abstract method
     */
    
public function testAddStmtToAbstractMethodError() {
        
$this->createMethodBuilder('test')
            ->
makeAbstract()
            ->
addStmt(new Print_(new String_('test')))
        ;
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Cannot make method with statements abstract
     */
    
public function testMakeMethodWithStmtsAbstractError() {
        
$this->createMethodBuilder('test')
            ->
addStmt(new Print_(new String_('test')))
            ->
makeAbstract()
        ;
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Expected parameter node, got "Name"
     */
    
public function testInvalidParamError() {
        
$this->createMethodBuilder('test')
            ->
addParam(new NodeName('foo'))
        ;
    }
}
Онлайн: 0
Реклама