1 | <?php |
||
18 | class BaseSniffTest extends PHPUnit_Framework_TestCase |
||
|
|||
19 | { |
||
20 | /** |
||
21 | * The PHP_CodeSniffer object used for testing. |
||
22 | * |
||
23 | * @var PHP_CodeSniffer |
||
24 | */ |
||
25 | protected static $phpcs = null; |
||
26 | |||
27 | /** |
||
28 | * An array of PHPCS results by filename and PHP version. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | public static $sniffFiles = array(); |
||
33 | |||
34 | /** |
||
35 | * Sets up this unit test. |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | public static function setUpBeforeClass() |
||
54 | |||
55 | /** |
||
56 | * Tear down after each test |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public static function tearDownAfterClass() |
||
66 | |||
67 | /** |
||
68 | * Sniff a file and return resulting file object |
||
69 | * |
||
70 | * @param string $filename Filename to sniff |
||
71 | * @param string $targetPhpVersion Value of 'testVersion' to set on PHPCS object |
||
72 | * @return PHP_CodeSniffer_File File object|false |
||
73 | */ |
||
74 | public function sniffFile($filename, $targetPhpVersion = null) |
||
95 | |||
96 | /** |
||
97 | * Assert a PHPCS error on a particular line number |
||
98 | * |
||
99 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
100 | * @param int $lineNumber Line number |
||
101 | * @param string $expectedMessage Expected error message (assertContains) |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function assertError(PHP_CodeSniffer_File $file, $lineNumber, $expectedMessage) |
||
110 | |||
111 | /** |
||
112 | * Assert a PHPCS warning on a particular line number |
||
113 | * |
||
114 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
115 | * @param int $lineNumber Line number |
||
116 | * @param string $expectedMessage Expected message (assertContains) |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function assertWarning(PHP_CodeSniffer_File $file, $lineNumber, $expectedMessage) |
||
125 | |||
126 | /** |
||
127 | * Assert a PHPCS error or warning on a particular line number. |
||
128 | * |
||
129 | * @param array $issues Array of issues of a particular type. |
||
130 | * @param string $type The type of issues, either 'error' or 'warning'. |
||
131 | * @param int $lineNumber Line number. |
||
132 | * @param string $expectedMessage Expected message (assertContains). |
||
133 | * @return bool |
||
134 | */ |
||
135 | private function assertForType($issues, $type, $lineNumber, $expectedMessage) |
||
154 | |||
155 | /** |
||
156 | * Assert no violation (warning or error) on a given line number |
||
157 | * |
||
158 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
159 | * @param mixed $lineNumber Line number |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function assertNoViolation(PHP_CodeSniffer_File $file, $lineNumber = 0) |
||
200 | |||
201 | /** |
||
202 | * Show violations in file by line number |
||
203 | * |
||
204 | * This is useful for debugging sniffs on a file |
||
205 | * |
||
206 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
207 | * @return void |
||
208 | */ |
||
209 | public function showViolations(PHP_CodeSniffer_File $file) |
||
218 | |||
219 | /** |
||
220 | * Gather all error messages by line number from phpcs file result |
||
221 | * |
||
222 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
223 | * @return array |
||
224 | */ |
||
225 | public function gatherErrors(PHP_CodeSniffer_File $file) |
||
231 | |||
232 | /** |
||
233 | * Gather all warning messages by line number from phpcs file result |
||
234 | * |
||
235 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
236 | * @return array |
||
237 | */ |
||
238 | public function gatherWarnings(PHP_CodeSniffer_File $file) |
||
244 | |||
245 | /** |
||
246 | * Gather all messages or a particular type by line number. |
||
247 | * |
||
248 | * @param array $IssuesArray Array of a particular type of issues, |
||
249 | * i.e. errors or warnings. |
||
250 | * @return array |
||
251 | */ |
||
252 | private function gatherIssues($issuesArray) |
||
270 | } |
||
271 | |||
272 |
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.