Completed
Push — develop ( 079ed4...346f28 )
by Jaap
10s
created

testFunctionWithoutNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
14
namespace phpDocumentor\Reflection\NodeVisitor;
15
16
use PhpParser\Node\Const_;
17
use PhpParser\Node\Name;
18
use PhpParser\Node\Scalar\String_;
19
use PhpParser\Node\Stmt\Class_;
20
use PhpParser\Node\Stmt\ClassConst;
21
use PhpParser\Node\Stmt\Function_;
22
use PhpParser\Node\Stmt\Namespace_;
23
use PhpParser\NodeTraverser;
24
25
/**
26
 * Testcase for FqsenResolver
27
 * @coversDefaultClass phpDocumentor\Reflection\NodeVisitor\ElementNameResolver
28
 * @covers ::<private>
29
 */
30
class ElementNameResolverTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @var ElementNameResolver
34
     */
35
    private $fixture;
36
37
    protected function setUp()
38
    {
39
        $this->fixture = new ElementNameResolver();
40
        $this->fixture->beforeTraverse([]);
41
    }
42
43
    /**
44
     * @covers ::enterNode
45
     */
46
    public function testFunctionWithoutNamespace()
47
    {
48
        $function = new Function_('myFunction');
49
        $this->fixture->enterNode($function);
50
51
        $this->assertEquals('\myFunction()', (string)$function->fqsen);
52
    }
53
54
    /**
55
     * @covers ::enterNode
56
     */
57
    public function testWithClass()
58
    {
59
        $class = new Class_('myClass');
60
        $this->fixture->enterNode($class);
61
62
        $this->assertEquals('\myClass', (string)$class->fqsen);
63
    }
64
65
    /**
66
     * If anonymous classes were processed, we would obtain a
67
     * InvalidArgumentException for an invalid Fqsen.
68
     *
69
     * @covers ::enterNode
70
     */
71
    public function testDoesNotEnterAnonymousClass()
72
    {
73
        $class = new Class_(null);
74
        $this->assertEquals(
75
            NodeTraverser::DONT_TRAVERSE_CHILDREN,
76
            $this->fixture->enterNode($class)
77
        );
78
    }
79
80
    /**
81
     * @covers ::enterNode
82
     */
83
    public function testClassConstant()
84
    {
85
        $const = new Const_('MY_CLASS', new String_('value'));
86
        $classConst = new ClassConst([$const]);
87
        $class = new Class_('myClass');
88
89
        $this->fixture->enterNode($class);
90
        $this->fixture->enterNode($classConst);
91
        $this->fixture->enterNode($const);
92
93
        $this->assertEquals('\\myClass::MY_CLASS', (string)$const->fqsen);
94
    }
95
96
    /**
97
     * @covers ::enterNode
98
     */
99
    public function testNamespacedConstant()
100
    {
101
        $const = new Const_('MY_CLASS', new String_('value'));
102
        $namespace = new Namespace_(new Name('name'));
103
104
        $this->fixture->enterNode($namespace);
105
        $this->fixture->enterNode($const);
106
107
        $this->assertEquals('\\name\\MY_CLASS', (string)$const->fqsen);
108
    }
109
}
110