Completed
Pull Request — master (#230)
by Juliette
03:24
created

BaseClass_TokenScopeTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 104
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Token scope test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Token scope function tests
11
 *
12
 * @uses    BaseClass_MethodTestFrame
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class BaseClass_TokenScopeTest extends BaseClass_MethodTestFrame
17
{
18
19
    public $filename = '../sniff-examples/utility-functions/token_has_scope.php';
20
21
    /**
22
     * testTokenHasScope
23
     *
24
     * @group utilityFunctions
25
     *
26
     * @dataProvider dataTokenHasScope
27
     *
28
     * @covers PHPCompatibility_Sniff::tokenHasScope
29
     *
30
     * @param int    $stackPtr Stack pointer for an arbitrary token in the test file.
31
     * @param string $expected The expected boolean return value.
32
     */
33
    public function testTokenHasScope($stackPtr, $expected, $validTokens = null)
34
    {
35
        $result = $this->helperClass->tokenHasScope($this->_phpcsFile, $stackPtr, $validTokens);
36
        $this->assertSame($expected, $result);
37
    }
38
39
    /**
40
     * dataTokenHasScope
41
     *
42
     * @see testTokenHasScope()
43
     *
44
     * @return array
45
     */
46
    public function dataTokenHasScope()
47
    {
48
        return array(
49
            // No scope.
50
            array(2, false), // $var
51
52
            // Various scopes.
53
            array(23, true), // echo within if
54
            array(23, true, array( T_IF ) ), // echo within if
55
            array(23, false, array( T_SWITCH ) ), // echo within if
56
57
            array(45, true), // echo within else-if
58
            array(45, true, array( T_ELSEIF ) ), // echo within else-if
59
            array(45, false, array( T_IF ) ), // echo within else-if
60
61
            array(57, true), // echo within else
62
            array(86, true), // echo within for
63
            array(107, true), // echo within foreach
64
65
            array(123, true), // case within switch
66
            array(123, true, array(T_SWITCH)), // case within switch
67
            array(123, false, array(T_CASE)), // case within switch
68
69
            array(129, true), // echo within case within switch
70
            array(129, true, array(T_SWITCH)), // echo within case within switch
71
            array(129, true, array(T_CASE)), // echo within case within switch
72
            array(129, true, array(T_SWITCH, T_CASE)), // echo within case within switch
73
            array(129, true, array(T_SWITCH, T_IF)), // echo within case within switch
74
            array(129, false, array(T_ELSEIF, T_IF)), // echo within case within switch
75
76
            array(139, true), // default within switch
77
            array(143, true), // echo within default within switch
78
79
            array(164, true), // echo within function
80
            array(164, true, array(T_FUNCTION)), // echo within function
81
        );
82
    }
83
84
    /**
85
     * testInClassScope
86
     *
87
     * @group utilityFunctions
88
     *
89
     * @dataProvider dataInClassScope
90
     *
91
     * @covers PHPCompatibility_Sniff::inClassScope
92
     *
93
     * @param int    $stackPtr Stack pointer for an arbitrary token in the test file.
94
     * @param string $expected The expected boolean return value.
95
     */
96
    public function testInClassScope($stackPtr, $expected)
97
    {
98
        $result = $this->helperClass->inClassScope($this->_phpcsFile, $stackPtr);
99
        $this->assertSame($expected, $result);
100
    }
101
102
    /**
103
     * dataInClassScope
104
     *
105
     * @see testInClassScope()
106
     *
107
     * @return array
108
     */
109
    public function dataInClassScope()
110
    {
111
        return array(
112
            array(181, true), // $property
113
            array(185, true), // function
114
            array(202, false), // function
115
            array(220, true), // function
116
        );
117
    }
118
119
}
120