1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* New use group declaration sniff tests |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* New use group declaration sniff tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Wim Godden <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class NewGroupUseDeclarationsSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
const TEST_FILE = 'sniff-examples/new_group_use_declarations.php'; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
if (version_compare(PHP_CodeSniffer::VERSION, '2.3.4', '<')) { |
24
|
|
|
$this->markTestSkipped(); |
25
|
|
|
} |
26
|
|
|
else { |
27
|
|
|
parent::setUp(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* testGroupUseDeclaration |
33
|
|
|
* |
34
|
|
|
* @dataProvider dataGroupUseDeclaration |
35
|
|
|
* |
36
|
|
|
* @param int $line The line number. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function testGroupUseDeclaration($line) |
41
|
|
|
{ |
42
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.6'); |
43
|
|
|
$this->assertError($file, $line, 'Group use declarations are not allowed in PHP 5.6 or earlier'); |
44
|
|
|
|
45
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
46
|
|
|
$this->assertNoViolation($file, $line); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Data provider. |
51
|
|
|
* |
52
|
|
|
* @see testGroupUseDeclaration() |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function dataGroupUseDeclaration() |
57
|
|
|
{ |
58
|
|
|
return array( |
59
|
|
|
array(13), |
60
|
|
|
array(14), |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* testValidUseDeclaration |
67
|
|
|
* |
68
|
|
|
* @dataProvider dataValidUseDeclaration |
69
|
|
|
* |
70
|
|
|
* @param int $line The line number. |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function testValidUseDeclaration($line) |
75
|
|
|
{ |
76
|
|
|
$file = $this->sniffFile(self::TEST_FILE); |
77
|
|
|
$this->assertNoViolation($file, $line); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Data provider. |
82
|
|
|
* |
83
|
|
|
* @see testValidUseDeclaration() |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function dataValidUseDeclaration() |
88
|
|
|
{ |
89
|
|
|
return array( |
90
|
|
|
array(4), |
91
|
|
|
array(5), |
92
|
|
|
array(6), |
93
|
|
|
array(8), |
94
|
|
|
array(9), |
95
|
|
|
array(10), |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.