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

namespace PhpParserBuilder;

use 
PhpParserNode;
use 
PhpParserNodeExpr;
use 
PhpParserNodeScalar;

class 
ParamTest extends PHPUnit_Framework_TestCase
{
    public function 
createParamBuilder($name) {
        return new 
Param($name);
    }

    
/**
     * @dataProvider provideTestDefaultValues
     */
    
public function testDefaultValues($value$expectedValueNode) {
        
$node $this->createParamBuilder('test')
            ->
setDefault($value)
            ->
getNode()
        ;

        
$this->assertEquals($expectedValueNode$node->default);
    }

    public function 
provideTestDefaultValues() {
        return array(
            array(
                
null,
                new 
ExprConstFetch(new NodeName('null'))
            ),
            array(
                
true,
                new 
ExprConstFetch(new NodeName('true'))
            ),
            array(
                
false,
                new 
ExprConstFetch(new NodeName('false'))
            ),
            array(
                
31415,
                new 
ScalarLNumber(31415)
            ),
            array(
                
3.1415,
                new 
ScalarDNumber(3.1415)
            ),
            array(
                
'Hallo World',
                new 
ScalarString_('Hallo World')
            ),
            array(
                array(
123),
                new 
ExprArray_(array(
                    new 
ExprArrayItem(new ScalarLNumber(1)),
                    new 
ExprArrayItem(new ScalarLNumber(2)),
                    new 
ExprArrayItem(new ScalarLNumber(3)),
                ))
            ),
            array(
                array(
'foo' => 'bar''bar' => 'foo'),
                new 
ExprArray_(array(
                    new 
ExprArrayItem(
                        new 
ScalarString_('bar'),
                        new 
ScalarString_('foo')
                    ),
                    new 
ExprArrayItem(
                        new 
ScalarString_('foo'),
                        new 
ScalarString_('bar')
                    ),
                ))
            ),
            array(
                new 
ScalarMagicConstDir,
                new 
ScalarMagicConstDir
            
)
        );
    }

    public function 
testTypeHints() {
        
$node $this->createParamBuilder('test')
            ->
setTypeHint('array')
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
NodeParam('test'null'array'),
            
$node
        
);

        
$node $this->createParamBuilder('test')
            ->
setTypeHint('callable')
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
NodeParam('test'null'callable'),
            
$node
        
);

        
$node $this->createParamBuilder('test')
            ->
setTypeHint('SomeClass')
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
NodeParam('test'null, new NodeName('SomeClass')),
            
$node
        
);
    }

    public function 
testByRef() {
        
$node $this->createParamBuilder('test')
            ->
makeByRef()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
NodeParam('test'nullnulltrue),
            
$node
        
);
    }
}
Онлайн: 0
Реклама