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() |
||
43 | |||
44 | /** |
||
45 | * Sets up this unit test. |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | protected function setUp() |
||
63 | |||
64 | /** |
||
65 | * Tear down after each test |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function tearDown() |
||
70 | { |
||
71 | // Reset any settingsStandard (targetPhpVersion) |
||
72 | self::$phpcs->cli->settingsStandard = array(); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Tear down after each test |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public static function tearDownAfterClass() |
||
84 | |||
85 | /** |
||
86 | * Sniff a file and return resulting file object |
||
87 | * |
||
88 | * @param string $filename Filename to sniff |
||
89 | * @param string $targetPhpVersion Value of 'testVersion' to set on PHPCS object |
||
90 | * @return PHP_CodeSniffer_File File object|false |
||
91 | */ |
||
92 | public function sniffFile($filename, $targetPhpVersion = null) |
||
112 | |||
113 | /** |
||
114 | * Assert a PHPCS error on a particular line number |
||
115 | * |
||
116 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
117 | * @param int $lineNumber Line number |
||
118 | * @param string $expectedMessage Expected error message (assertContains) |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function assertError(PHP_CodeSniffer_File $file, $lineNumber, $expectedMessage) |
||
127 | |||
128 | /** |
||
129 | * Assert a PHPCS warning on a particular line number |
||
130 | * |
||
131 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
132 | * @param int $lineNumber Line number |
||
133 | * @param string $expectedMessage Expected message (assertContains) |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function assertWarning(PHP_CodeSniffer_File $file, $lineNumber, $expectedMessage) |
||
142 | |||
143 | /** |
||
144 | * Assert a PHPCS error or warning on a particular line number. |
||
145 | * |
||
146 | * @param array $issues Array of issues of a particular type. |
||
147 | * @param string $type The type of issues, either 'error' or 'warning'. |
||
148 | * @param int $lineNumber Line number. |
||
149 | * @param string $expectedMessage Expected message (assertContains). |
||
150 | * @return bool |
||
151 | */ |
||
152 | private function assertForType($issues, $type, $lineNumber, $expectedMessage) |
||
171 | |||
172 | /** |
||
173 | * Assert no violation (warning or error) on a given line number |
||
174 | * |
||
175 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
176 | * @param mixed $lineNumber Line number |
||
177 | * @return bool |
||
178 | */ |
||
179 | public function assertNoViolation(PHP_CodeSniffer_File $file, $lineNumber = 0) |
||
217 | |||
218 | /** |
||
219 | * Show violations in file by line number |
||
220 | * |
||
221 | * This is useful for debugging sniffs on a file |
||
222 | * |
||
223 | * @param PHP_CodeSniffer_File $file Codesniffer file object |
||
224 | * @return void |
||
225 | */ |
||
226 | public function showViolations(PHP_CodeSniffer_File $file) |
||
235 | |||
236 | /** |
||
237 | * Gather all error messages by line number from phpcs file result |
||
238 | * |
||
239 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
240 | * @return array |
||
241 | */ |
||
242 | public function gatherErrors(PHP_CodeSniffer_File $file) |
||
248 | |||
249 | /** |
||
250 | * Gather all warning messages by line number from phpcs file result |
||
251 | * |
||
252 | * @param PHP_CodeSniffer_File $file Codesniffer File object |
||
253 | * @return array |
||
254 | */ |
||
255 | public function gatherWarnings(PHP_CodeSniffer_File $file) |
||
261 | |||
262 | /** |
||
263 | * Gather all messages or a particular type by line number. |
||
264 | * |
||
265 | * @param array $IssuesArray Array of a particular type of issues, |
||
266 | * i.e. errors or warnings. |
||
267 | * @return array |
||
268 | */ |
||
269 | private function gatherIssues($issuesArray) |
||
287 | } |
||
288 | |||
289 |
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.