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

namespace PhpParserBuilder;

use 
PhpParserNode;
use 
PhpParserNodeStmt;
use 
PhpParserNodeScalarDNumber;
use 
PhpParserComment;

class 
InterfaceTest extends PHPUnit_Framework_TestCase
{
    
/** @var Interface_ */
    
protected $builder;

    protected function 
setUp() {
        
$this->builder = new Interface_('Contract');
    }

    private function 
dump($node) {
        
$pp = new PhpParserPrettyPrinterStandard;
        return 
$pp->prettyPrint(array($node));
    }

    public function 
testEmpty() {
        
$contract $this->builder->getNode();
        
$this->assertInstanceOf('PhpParserNodeStmtInterface_'$contract);
        
$this->assertSame('Contract'$contract->name);
    }

    public function 
testExtending() {
        
$contract $this->builder->extend('SpaceRoot1''Root2')->getNode();
        
$this->assertEquals(
            new 
StmtInterface_('Contract', array(
                
'extends' => array(
                    new 
NodeName('SpaceRoot1'),
                    new 
NodeName('Root2')
                ),
            )), 
$contract
        
);
    }

    public function 
testAddMethod() {
        
$method = new StmtClassMethod('doSomething');
        
$contract $this->builder->addStmt($method)->getNode();
        
$this->assertSame(array($method), $contract->stmts);
    }

    public function 
testAddConst() {
        
$const = new StmtClassConst(array(
            new 
NodeConst_('SPEED_OF_LIGHT', new DNumber(299792458.0))
        ));
        
$contract $this->builder->addStmt($const)->getNode();
        
$this->assertSame(299792458.0$contract->stmts[0]->consts[0]->value->value);
    }

    public function 
testOrder() {
        
$const = new StmtClassConst(array(
            new 
NodeConst_('SPEED_OF_LIGHT', new DNumber(299792458))
        ));
        
$method = new StmtClassMethod('doSomething');
        
$contract $this->builder
            
->addStmt($method)
            ->
addStmt($const)
            ->
getNode()
        ;

        
$this->assertInstanceOf('PhpParserNodeStmtClassConst'$contract->stmts[0]);
        
$this->assertInstanceOf('PhpParserNodeStmtClassMethod'$contract->stmts[1]);
    }

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

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

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Unexpected node of type "Stmt_PropertyProperty"
     */
    
public function testInvalidStmtError() {
        
$this->builder->addStmt(new StmtPropertyProperty('invalid'));
    }

    public function 
testFullFunctional() {
        
$const = new StmtClassConst(array(
            new 
NodeConst_('SPEED_OF_LIGHT', new DNumber(299792458))
        ));
        
$method = new StmtClassMethod('doSomething');
        
$contract $this->builder
            
->addStmt($method)
            ->
addStmt($const)
            ->
getNode()
        ;

        eval(
$this->dump($contract));

        
$this->assertTrue(interface_exists('Contract'false));
    }
}
Онлайн: 0
Реклама