Completed
Push — master ( 50932b...737862 )
by Wim
9s
created

NewKeywordsSniffTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 12
c 7
b 2
f 1
lcom 1
cbo 1
dl 0
loc 160
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testDirMagicConstant() 0 6 1
A testNamespaceKeyword() 0 6 1
A testNamespaceConstant() 0 6 1
A testUse() 0 6 1
A testNowdoc() 0 7 1
A testInsteadOf() 0 6 1
A testTraitKeyword() 0 6 1
A testTraitConstant() 0 6 1
A testYield() 0 6 1
A testFinally() 0 6 1
A testConst() 0 8 1
A testHaltCompiler() 0 6 1
1
<?php
2
/**
3
 * New keywords sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New keywords sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class NewKeywordsSniffTest extends BaseSniffTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    /**
19
     * Test allow_url_include
20
     *
21
     * @return void
22
     */
23
    public function testDirMagicConstant()
24
    {
25
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
26
27
        $this->assertError($file, 3, "__DIR__ magic constant is not present in PHP version 5.2 or earlier");
28
    }
29
30
    /**
31
     * Test insteadof
32
     *
33
     * @requires PHP 5.4
34
     * @return void
35
     */
36
    public function testInsteadOf()
37
    {
38
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.3');
39
40
        $this->assertError($file, 15, "\"insteadof\" keyword (for traits) is not present in PHP version 5.3 or earlier");
41
    }
42
43
    /**
44
     * Test namespace keyword
45
     *
46
     * @return void
47
     */
48
    public function testNamespaceKeyword()
49
    {
50
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
51
52
        $this->assertError($file, 20, "\"namespace\" keyword is not present in PHP version 5.2 or earlier");
53
    }
54
55
    /**
56
     * testNamespaceConstant
57
     *
58
     * @return void
59
     */
60
    public function testNamespaceConstant()
61
    {
62
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
63
64
        $this->assertError($file, 22, "__NAMESPACE__ magic constant is not present in PHP version 5.2 or earlier");
65
    }
66
67
    /**
68
     * Test trait keyword
69
     *
70
     * @requires PHP 5.4
71
     * @return void
72
     */
73
    public function testTraitKeyword()
74
    {
75
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.3');
76
77
        $this->assertError($file, 24, "\"trait\" keyword is not present in PHP version 5.3 or earlier");
78
    }
79
80
    /**
81
     * Test trait magic constant
82
     *
83
     * @requires PHP 5.4
84
     * @return void
85
     */
86
    public function testTraitConstant()
87
    {
88
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.3');
89
90
        $this->assertError($file, 26, "__TRAIT__ magic constant is not present in PHP version 5.3 or earlier");
91
    }
92
93
    /**
94
     * Test the use keyword
95
     *
96
     * @return void
97
     */
98
    public function testUse()
99
    {
100
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
101
102
        $this->assertError($file, 14, "\"use\" keyword (for traits/namespaces/anonymous functions) is not present in PHP version 5.2 or earlier");
103
    }
104
105
    /**
106
     * Test yield
107
     *
108
     * @requires PHP 5.5
109
     * @return void
110
     */
111
    public function testYield()
112
    {
113
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.4');
114
115
        $this->assertError($file, 33, "\"yield\" keyword (for generators) is not present in PHP version 5.4 or earlier");
116
    }
117
118
    /**
119
     * testFinally
120
     *
121
     * @requires PHP 5.5
122
     * @return void
123
     */
124
    public function testFinally()
125
    {
126
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.4');
127
128
        $this->assertError($file, 9, "\"finally\" keyword (in exception handling) is not present in PHP version 5.4 or earlier");
129
    }
130
131
    /**
132
     * testNowdoc
133
     *
134
     * @requires PHP 5.3
135
     * @return void
136
     */
137
    public function testNowdoc()
138
    {
139
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
140
141
        $this->assertError($file, 37, "nowdoc functionality is not present in PHP version 5.2 or earlier");
142
        $this->assertError($file, 41, "nowdoc functionality is not present in PHP version 5.2 or earlier");
143
    }
144
145
    /**
146
     * testConst
147
     *
148
     * @requires PHP 5.3 if used outside class context
149
     * @return void
150
     */
151
    public function testConst()
152
    {
153
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
154
155
        $this->assertError($file, 43, "\"const\" keyword is not present in PHP version 5.2 or earlier");
156
        $this->assertNoViolation($file, 46);
157
        $this->assertNoViolation($file, 47);
158
    }
159
160
    /**
161
     * testHaltCompiler
162
     *
163
     * Usage of `__halt_compiler()` cannot be tested on its own token as the compiler will be halted...
164
     * So testing that any violations created *after* the compiler is halted will not be reported.
165
     *
166
     * @requires PHP 5.1
167
     * @return void
168
     */
169
    public function testHaltCompiler()
170
    {
171
        $file = $this->sniffFile('sniff-examples/new_keywords.php', '5.2');
172
173
        $this->assertNoViolation($file, 53);
174
    }
175
}
176