Skip to content

Commit a82cb4d

Browse files
authored
Merge pull request #303 from PHPCSStandards/feature/tests-update-for-phpcs-3.9.0
UseStatements/KeywordSpacing: add missing "fixed" test file
2 parents 11d387c + 8856f8b commit a82cb4d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
/*
4+
* The behaviour of the sniff for this code sample will be different depending on the PHP version.
5+
* For PHP < 8.0, it will correctly flag this as "no space" after the `use` keyword.
6+
* For PHP 8.0+, this will no longer be flagged as keywords are allowed in namespaced names,
7+
* so the `use` is tokenized as `T_STRING` instead of `T_USE` and won't be flagged.
8+
*
9+
* For this reason, there is no "fixed" file included as the test would not be able to pass on PHP 8.0+.
10+
*/
11+
use \Util\MyOtherClass;

Universal/Tests/UseStatements/KeywordSpacingUnitTest.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,34 @@
2222
final class KeywordSpacingUnitTest extends AbstractSniffUnitTest
2323
{
2424

25+
/**
26+
* Get a list of all test files to check.
27+
*
28+
* @param string $testFileBase The base path that the unit tests files will have.
29+
*
30+
* @return array<string>
31+
*/
32+
protected function getTestFiles($testFileBase)
33+
{
34+
$testFiles = parent::getTestFiles($testFileBase);
35+
36+
if (\PHP_VERSION_ID < 80000) {
37+
return $testFiles;
38+
}
39+
40+
// The issue being tested in the "2" test case file cannot be flagged/fixed on PHP 8.0+.
41+
$target = 'KeywordSpacingUnitTest.2.inc';
42+
$length = \strlen($target);
43+
foreach ($testFiles as $i => $fileName) {
44+
if (\substr($fileName, -$length) === $target) {
45+
unset($testFiles[$i]);
46+
break;
47+
}
48+
}
49+
50+
return $testFiles;
51+
}
52+
2553
/**
2654
* Returns the lines where errors should occur.
2755
*
@@ -55,10 +83,6 @@ public function getErrorList($testFile = '')
5583
];
5684

5785
case 'KeywordSpacingUnitTest.2.inc':
58-
if (\PHP_VERSION_ID >= 80000) {
59-
return [];
60-
}
61-
6286
return [
6387
11 => 1,
6488
];

0 commit comments

Comments
 (0)