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

namespace PhpParserBuilder;

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

class 
FunctionTest extends PHPUnit_Framework_TestCase
{
    public function 
createFunctionBuilder($name) {
        return new 
Function_($name);
    }

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

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

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

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

        
$this->assertEquals(
            new 
StmtFunction_('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->createFunctionBuilder('test')
            ->
addStmt($stmt1)
            ->
addStmts(array($stmt2$stmt3))
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtFunction_('test', array(
                
'stmts' => array($stmt1$stmt2$stmt3)
            )),
            
$node
        
);
    }

    public function 
testDocComment() {
        
$node $this->createFunctionBuilder('test')
            ->
setDocComment('/** Test */')
            ->
getNode();

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

    public function 
testReturnType() {
        
$node $this->createFunctionBuilder('test')
            ->
setReturnType('bool')
            ->
getNode();

        
$this->assertEquals(new StmtFunction_('test', array(
            
'returnType' => 'bool'
        
), array()), $node);
    }

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