1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Constant arrays using define in PHP 7.0 sniff test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Constant arrays using define in PHP 7.0 sniff test file |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Wim Godden <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ConstantArraysUsingDefineSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
const TEST_FILE = 'sniff-examples/constant_arrays_using_define.php'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Verify that checking for a specific version works |
22
|
|
|
* |
23
|
|
|
* @group constantArraysUsingDefine |
24
|
|
|
* |
25
|
|
|
* @dataProvider dataConstantArraysUsingDefine |
26
|
|
|
* |
27
|
|
|
* @param int $line The line number. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
public function testConstantArraysUsingDefine($line) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
34
|
|
|
$this->assertNoViolation($file, $line); |
35
|
|
|
|
36
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
37
|
|
|
$this->assertError($file, $line, 'Constant arrays using define are not allowed in PHP 5.6 or earlier'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Data provider dataConstantArraysUsingDefine. |
42
|
|
|
* |
43
|
|
|
* @see testConstantArraysUsingDefine() |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function dataConstantArraysUsingDefine() |
48
|
|
|
{ |
49
|
|
|
return array( |
50
|
|
|
array(3), |
51
|
|
|
array(9), |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* testNoViolation |
58
|
|
|
* |
59
|
|
|
* @group constantArraysUsingDefine |
60
|
|
|
* |
61
|
|
|
* @dataProvider dataNoViolation |
62
|
|
|
* |
63
|
|
|
* @param int $line The line number. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
public function testNoViolation($line) |
68
|
|
|
{ |
69
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.3'); |
70
|
|
|
$this->assertNoViolation($file, $line); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Data provider. |
75
|
|
|
* |
76
|
|
|
* @see testNoViolation() |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function dataNoViolation() |
81
|
|
|
{ |
82
|
|
|
return array( |
83
|
|
|
array(15), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
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.