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

namespace PhpParserBuilder;

use 
PhpParserComment;
use 
PhpParserNode;
use 
PhpParserNodeName;
use 
PhpParserNodeStmt;

class 
ClassTest extends PHPUnit_Framework_TestCase
{
    protected function 
createClassBuilder($class) {
        return new 
Class_($class);
    }

    public function 
testExtendsImplements() {
        
$node $this->createClassBuilder('SomeLogger')
            ->
extend('BaseLogger')
            ->
implement('NamespacedLogger', new Name('SomeInterface'))
            ->
implement('FullyQualified''namespaceNamespaceRelative')
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClass_('SomeLogger', array(
                
'extends' => new Name('BaseLogger'),
                
'implements' => array(
                    new 
Name('NamespacedLogger'),
                    new 
Name('SomeInterface'),
                    new 
NameFullyQualified('FullyQualified'),
                    new 
NameRelative('NamespaceRelative'),
                ),
            )),
            
$node
        
);
    }

    public function 
testAbstract() {
        
$node $this->createClassBuilder('Test')
            ->
makeAbstract()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClass_('Test', array(
                
'type' => StmtClass_::MODIFIER_ABSTRACT
            
)),
            
$node
        
);
    }

    public function 
testFinal() {
        
$node $this->createClassBuilder('Test')
            ->
makeFinal()
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClass_('Test', array(
                
'type' => StmtClass_::MODIFIER_FINAL
            
)),
            
$node
        
);
    }

    public function 
testStatementOrder() {
        
$method = new StmtClassMethod('testMethod');
        
$property = new StmtProperty(
            
StmtClass_::MODIFIER_PUBLIC,
            array(new 
StmtPropertyProperty('testProperty'))
        );
        
$const = new StmtClassConst(array(
            new 
NodeConst_('TEST_CONST', new NodeScalarString_('ABC'))
        ));
        
$use = new StmtTraitUse(array(new Name('SomeTrait')));

        
$node $this->createClassBuilder('Test')
            ->
addStmt($method)
            ->
addStmt($property)
            ->
addStmts(array($const$use))
            ->
getNode()
        ;

        
$this->assertEquals(
            new 
StmtClass_('Test', array(
                
'stmts' => array($use$const$property$method)
            )),
            
$node
        
);
    }

    public function 
testDocComment() {
        
$docComment = <<<'DOC'
/**
 * Test
 */
DOC;
        
$class $this->createClassBuilder('Test')
            ->
setDocComment($docComment)
            ->
getNode();

        
$this->assertEquals(
            new 
StmtClass_('Test', array(), array(
                
'comments' => array(
                    new 
CommentDoc($docComment)
                )
            )),
            
$class
        
);

        
$class $this->createClassBuilder('Test')
            ->
setDocComment(new CommentDoc($docComment))
            ->
getNode();

        
$this->assertEquals(
            new 
StmtClass_('Test', array(), array(
                
'comments' => array(
                    new 
CommentDoc($docComment)
                )
            )),
            
$class
        
);
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Unexpected node of type "Stmt_Echo"
     */
    
public function testInvalidStmtError() {
        
$this->createClassBuilder('Test')
            ->
addStmt(new StmtEcho_(array()))
        ;
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Doc comment must be a string or an instance of PhpParserCommentDoc
     */
    
public function testInvalidDocComment() {
        
$this->createClassBuilder('Test')
            ->
setDocComment(new Comment('Test'));
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Name cannot be empty
     */
    
public function testEmptyName() {
        
$this->createClassBuilder('Test')
            ->
extend('');
    }

    
/**
     * @expectedException LogicException
     * @expectedExceptionMessage Name must be a string or an instance of PhpParserNodeName
     */
    
public function testInvalidName() {
        
$this->createClassBuilder('Test')
            ->
extend(array('Foo'));
    }
}
Онлайн: 0
Реклама