1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* New language constructs sniff test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* New language constructs sniff tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Jansen Price <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class NewLanguageConstructsSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
const TEST_FILE = 'sniff-examples/new_language_constructs.php'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* testNamespaceSeparator |
22
|
|
|
* |
23
|
|
|
* @group NewLanguageConstructs |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function testNamespaceSeparator() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.2'); |
30
|
|
|
$this->assertError($file, 3, 'the \ operator (for namespaces) is not present in PHP version 5.2 or earlier'); |
31
|
|
|
|
32
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.3'); |
33
|
|
|
$this->assertNoViolation($file, 3); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* testPow |
38
|
|
|
* |
39
|
|
|
* @group NewLanguageConstructs |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function testPow() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.5'); |
46
|
|
|
$this->assertError($file, 5, "power operator (**) is not present in PHP version 5.5 or earlier"); |
47
|
|
|
|
48
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
49
|
|
|
$this->assertNoViolation($file, 5); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* testPowEquals |
54
|
|
|
* |
55
|
|
|
* @group NewLanguageConstructs |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function testPowEquals() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.5'); |
62
|
|
|
$this->assertError($file, 6, "power assignment operator (**=) is not present in PHP version 5.5 or earlier"); |
63
|
|
|
|
64
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
65
|
|
|
$this->assertNoViolation($file, 6); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* testSpaceship |
70
|
|
|
* |
71
|
|
|
* @group NewLanguageConstructs |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public function testSpaceship() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
78
|
|
|
$this->assertError($file, 12, "spaceship operator (<=>) is not present in PHP version 5.6 or earlier"); |
79
|
|
|
|
80
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
81
|
|
|
$this->assertNoViolation($file, 12); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Coalescing operator |
86
|
|
|
* |
87
|
|
|
* @group NewLanguageConstructs |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function testCoalescing() |
92
|
|
|
{ |
93
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
94
|
|
|
$this->assertError($file, 8, "null coalescing operator (??) is not present in PHP version 5.6 or earlier"); |
95
|
|
|
$this->assertError($file, 10, "null coalescing operator (??) is not present in PHP version 5.6 or earlier"); |
96
|
|
|
|
97
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
98
|
|
|
$this->assertNoViolation($file, 8); |
99
|
|
|
$this->assertNoViolation($file, 10); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Variadic functions using ... |
104
|
|
|
* |
105
|
|
|
* @group NewLanguageConstructs |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
View Code Duplication |
public function testEllipsis() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.5'); |
112
|
|
|
$this->assertError($file, 14, "variadic functions using ... is not present in PHP version 5.5 or earlier"); |
113
|
|
|
|
114
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
115
|
|
|
$this->assertNoViolation($file, 14); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.