@@ -16,20 +16,20 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Runs the tests and collects their result in a TestResult. |
|
21 | - * |
|
22 | - * @param \PHPUnit\Framework\TestResult $result A test result. |
|
23 | - * |
|
24 | - * @return \PHPUnit\Framework\TestResult |
|
25 | - */ |
|
26 | - public function run(TestResult $result=null) |
|
27 | - { |
|
28 | - $result = parent::run($result); |
|
29 | - printPHPCodeSnifferTestOutput(); |
|
30 | - return $result; |
|
31 | - |
|
32 | - }//end run() |
|
19 | + /** |
|
20 | + * Runs the tests and collects their result in a TestResult. |
|
21 | + * |
|
22 | + * @param \PHPUnit\Framework\TestResult $result A test result. |
|
23 | + * |
|
24 | + * @return \PHPUnit\Framework\TestResult |
|
25 | + */ |
|
26 | + public function run(TestResult $result=null) |
|
27 | + { |
|
28 | + $result = parent::run($result); |
|
29 | + printPHPCodeSnifferTestOutput(); |
|
30 | + return $result; |
|
31 | + |
|
32 | + }//end run() |
|
33 | 33 | |
34 | 34 | |
35 | 35 | }//end class |
@@ -23,9 +23,9 @@ |
||
23 | 23 | * |
24 | 24 | * @return \PHPUnit\Framework\TestResult |
25 | 25 | */ |
26 | - public function run(TestResult $result=null) |
|
26 | + public function run( TestResult $result = null ) |
|
27 | 27 | { |
28 | - $result = parent::run($result); |
|
28 | + $result = parent::run( $result ); |
|
29 | 29 | printPHPCodeSnifferTestOutput(); |
30 | 30 | return $result; |
31 | 31 |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | use PHPUnit\Framework\TestSuite as PHPUnit_TestSuite; |
13 | 13 | use PHPUnit\Framework\TestResult; |
14 | 14 | |
15 | -class TestSuite extends PHPUnit_TestSuite |
|
16 | -{ |
|
15 | +class TestSuite extends PHPUnit_TestSuite { |
|
17 | 16 | |
18 | 17 | |
19 | 18 | /** |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | * |
24 | 23 | * @return \PHPUnit\Framework\TestResult |
25 | 24 | */ |
26 | - public function run(TestResult $result=null) |
|
27 | - { |
|
25 | + public function run(TestResult $result=null) { |
|
28 | 26 | $result = parent::run($result); |
29 | 27 | printPHPCodeSnifferTestOutput(); |
30 | 28 | return $result; |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | namespace PHP_CodeSniffer\Tests; |
11 | 11 | |
12 | 12 | if (is_file(__DIR__.'/../autoload.php') === true) { |
13 | - include_once 'Core/AllTests.php'; |
|
14 | - include_once 'Standards/AllSniffs.php'; |
|
13 | + include_once 'Core/AllTests.php'; |
|
14 | + include_once 'Standards/AllSniffs.php'; |
|
15 | 15 | } else { |
16 | - include_once 'CodeSniffer/Core/AllTests.php'; |
|
17 | - include_once 'CodeSniffer/Standards/AllSniffs.php'; |
|
16 | + include_once 'CodeSniffer/Core/AllTests.php'; |
|
17 | + include_once 'CodeSniffer/Standards/AllSniffs.php'; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | // PHPUnit 7 made the TestSuite run() method incompatible with |
@@ -22,42 +22,42 @@ discard block |
||
22 | 22 | // two different suite objects. |
23 | 23 | $phpunit7 = false; |
24 | 24 | if (class_exists('\PHPUnit\Runner\Version') === true) { |
25 | - $version = \PHPUnit\Runner\Version::id(); |
|
26 | - if ($version[0] === '7') { |
|
27 | - $phpunit7 = true; |
|
28 | - } |
|
25 | + $version = \PHPUnit\Runner\Version::id(); |
|
26 | + if ($version[0] === '7') { |
|
27 | + $phpunit7 = true; |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | if ($phpunit7 === true) { |
32 | - include_once 'TestSuite7.php'; |
|
32 | + include_once 'TestSuite7.php'; |
|
33 | 33 | } else { |
34 | - include_once 'TestSuite.php'; |
|
34 | + include_once 'TestSuite.php'; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | class PHP_CodeSniffer_AllTests |
38 | 38 | { |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Add all PHP_CodeSniffer test suites into a single test suite. |
|
43 | - * |
|
44 | - * @return \PHPUnit\Framework\TestSuite |
|
45 | - */ |
|
46 | - public static function suite() |
|
47 | - { |
|
48 | - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = []; |
|
49 | - $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = []; |
|
41 | + /** |
|
42 | + * Add all PHP_CodeSniffer test suites into a single test suite. |
|
43 | + * |
|
44 | + * @return \PHPUnit\Framework\TestSuite |
|
45 | + */ |
|
46 | + public static function suite() |
|
47 | + { |
|
48 | + $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = []; |
|
49 | + $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = []; |
|
50 | 50 | |
51 | - // Use a special PHP_CodeSniffer test suite so that we can |
|
52 | - // unset our autoload function after the run. |
|
53 | - $suite = new TestSuite('PHP CodeSniffer'); |
|
51 | + // Use a special PHP_CodeSniffer test suite so that we can |
|
52 | + // unset our autoload function after the run. |
|
53 | + $suite = new TestSuite('PHP CodeSniffer'); |
|
54 | 54 | |
55 | - $suite->addTest(Core\AllTests::suite()); |
|
56 | - $suite->addTest(Standards\AllSniffs::suite()); |
|
55 | + $suite->addTest(Core\AllTests::suite()); |
|
56 | + $suite->addTest(Standards\AllSniffs::suite()); |
|
57 | 57 | |
58 | - return $suite; |
|
58 | + return $suite; |
|
59 | 59 | |
60 | - }//end suite() |
|
60 | + }//end suite() |
|
61 | 61 | |
62 | 62 | |
63 | 63 | }//end class |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace PHP_CodeSniffer\Tests; |
11 | 11 | |
12 | -if (is_file(__DIR__.'/../autoload.php') === true) { |
|
12 | +if ( is_file( __DIR__ . '/../autoload.php' ) === true ) { |
|
13 | 13 | include_once 'Core/AllTests.php'; |
14 | 14 | include_once 'Standards/AllSniffs.php'; |
15 | 15 | } else { |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | // older PHPUnit versions due to return type hints, so maintain |
22 | 22 | // two different suite objects. |
23 | 23 | $phpunit7 = false; |
24 | -if (class_exists('\PHPUnit\Runner\Version') === true) { |
|
24 | +if ( class_exists( '\PHPUnit\Runner\Version' ) === true ) { |
|
25 | 25 | $version = \PHPUnit\Runner\Version::id(); |
26 | - if ($version[0] === '7') { |
|
26 | + if ( $version[ 0 ] === '7' ) { |
|
27 | 27 | $phpunit7 = true; |
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | -if ($phpunit7 === true) { |
|
31 | +if ( $phpunit7 === true ) { |
|
32 | 32 | include_once 'TestSuite7.php'; |
33 | 33 | } else { |
34 | 34 | include_once 'TestSuite.php'; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function suite() |
47 | 47 | { |
48 | - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = []; |
|
49 | - $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = []; |
|
48 | + $GLOBALS[ 'PHP_CODESNIFFER_STANDARD_DIRS' ] = [ ]; |
|
49 | + $GLOBALS[ 'PHP_CODESNIFFER_TEST_DIRS' ] = [ ]; |
|
50 | 50 | |
51 | 51 | // Use a special PHP_CodeSniffer test suite so that we can |
52 | 52 | // unset our autoload function after the run. |
53 | - $suite = new TestSuite('PHP CodeSniffer'); |
|
53 | + $suite = new TestSuite( 'PHP CodeSniffer' ); |
|
54 | 54 | |
55 | - $suite->addTest(Core\AllTests::suite()); |
|
56 | - $suite->addTest(Standards\AllSniffs::suite()); |
|
55 | + $suite->addTest( Core\AllTests::suite() ); |
|
56 | + $suite->addTest( Standards\AllSniffs::suite() ); |
|
57 | 57 | |
58 | 58 | return $suite; |
59 | 59 |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | include_once 'TestSuite.php'; |
35 | 35 | } |
36 | 36 | |
37 | -class PHP_CodeSniffer_AllTests |
|
38 | -{ |
|
37 | +class PHP_CodeSniffer_AllTests { |
|
39 | 38 | |
40 | 39 | |
41 | 40 | /** |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | * |
44 | 43 | * @return \PHPUnit\Framework\TestSuite |
45 | 44 | */ |
46 | - public static function suite() |
|
47 | - { |
|
45 | + public static function suite() { |
|
48 | 46 | $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = []; |
49 | 47 | $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = []; |
50 | 48 |
@@ -23,428 +23,428 @@ |
||
23 | 23 | abstract class AbstractSniffUnitTest extends TestCase |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Enable or disable the backup and restoration of the $GLOBALS array. |
|
28 | - * Overwrite this attribute in a child class of TestCase. |
|
29 | - * Setting this attribute in setUp() has no effect! |
|
30 | - * |
|
31 | - * @var boolean |
|
32 | - */ |
|
33 | - protected $backupGlobals = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * The path to the standard's main directory. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $standardsDir = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * The path to the standard's test directory. |
|
44 | - * |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - public $testsDir = null; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Sets up this unit test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - protected function setUp() |
|
56 | - { |
|
57 | - $class = get_class($this); |
|
58 | - $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; |
|
59 | - $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; |
|
60 | - |
|
61 | - }//end setUp() |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Get a list of all test files to check. |
|
66 | - * |
|
67 | - * These will have the same base as the sniff name but different extensions. |
|
68 | - * We ignore the .php file as it is the class. |
|
69 | - * |
|
70 | - * @param string $testFileBase The base path that the unit tests files will have. |
|
71 | - * |
|
72 | - * @return string[] |
|
73 | - */ |
|
74 | - protected function getTestFiles($testFileBase) |
|
75 | - { |
|
76 | - $testFiles = []; |
|
77 | - |
|
78 | - $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); |
|
79 | - $di = new \DirectoryIterator($dir); |
|
80 | - |
|
81 | - foreach ($di as $file) { |
|
82 | - $path = $file->getPathname(); |
|
83 | - if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { |
|
84 | - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' && substr($path, -4) !== '.bak') { |
|
85 | - $testFiles[] = $path; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - // Put them in order. |
|
91 | - sort($testFiles); |
|
92 | - |
|
93 | - return $testFiles; |
|
94 | - |
|
95 | - }//end getTestFiles() |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Should this test be skipped for some reason. |
|
100 | - * |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - protected function shouldSkipTest() |
|
104 | - { |
|
105 | - return false; |
|
106 | - |
|
107 | - }//end shouldSkipTest() |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Tests the extending classes Sniff class. |
|
112 | - * |
|
113 | - * @return void |
|
114 | - * @throws \PHPUnit\Framework\Exception |
|
115 | - */ |
|
116 | - final public function testSniff() |
|
117 | - { |
|
118 | - // Skip this test if we can't run in this environment. |
|
119 | - if ($this->shouldSkipTest() === true) { |
|
120 | - $this->markTestSkipped(); |
|
121 | - } |
|
122 | - |
|
123 | - $sniffCode = Common::getSniffCode(get_class($this)); |
|
124 | - list($standardName, $categoryName, $sniffName) = explode('.', $sniffCode); |
|
125 | - |
|
126 | - $testFileBase = $this->testsDir.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; |
|
127 | - |
|
128 | - // Get a list of all test files to check. |
|
129 | - $testFiles = $this->getTestFiles($testFileBase); |
|
130 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'][] = $testFiles; |
|
131 | - |
|
132 | - if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG']) === true) { |
|
133 | - $config = $GLOBALS['PHP_CODESNIFFER_CONFIG']; |
|
134 | - } else { |
|
135 | - $config = new Config(); |
|
136 | - $config->cache = false; |
|
137 | - $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; |
|
138 | - } |
|
139 | - |
|
140 | - $config->standards = [$standardName]; |
|
141 | - $config->sniffs = [$sniffCode]; |
|
142 | - $config->ignored = []; |
|
143 | - |
|
144 | - if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS']) === false) { |
|
145 | - $GLOBALS['PHP_CODESNIFFER_RULESETS'] = []; |
|
146 | - } |
|
147 | - |
|
148 | - if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]) === false) { |
|
149 | - $ruleset = new Ruleset($config); |
|
150 | - $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName] = $ruleset; |
|
151 | - } |
|
152 | - |
|
153 | - $ruleset = $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]; |
|
154 | - |
|
155 | - $sniffFile = $this->standardsDir.DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'Sniff.php'; |
|
156 | - |
|
157 | - $sniffClassName = substr(get_class($this), 0, -8).'Sniff'; |
|
158 | - $sniffClassName = str_replace('\Tests\\', '\Sniffs\\', $sniffClassName); |
|
159 | - $sniffClassName = Common::cleanSniffClass($sniffClassName); |
|
160 | - |
|
161 | - $restrictions = [strtolower($sniffClassName) => true]; |
|
162 | - $ruleset->registerSniffs([$sniffFile], $restrictions, []); |
|
163 | - $ruleset->populateTokenListeners(); |
|
164 | - |
|
165 | - $failureMessages = []; |
|
166 | - foreach ($testFiles as $testFile) { |
|
167 | - $filename = basename($testFile); |
|
168 | - $oldConfig = $config->getSettings(); |
|
169 | - |
|
170 | - try { |
|
171 | - $this->setCliValues($filename, $config); |
|
172 | - $phpcsFile = new LocalFile($testFile, $ruleset, $config); |
|
173 | - $phpcsFile->process(); |
|
174 | - } catch (RuntimeException $e) { |
|
175 | - $this->fail('An unexpected exception has been caught: '.$e->getMessage()); |
|
176 | - } |
|
177 | - |
|
178 | - $failures = $this->generateFailureMessages($phpcsFile); |
|
179 | - $failureMessages = array_merge($failureMessages, $failures); |
|
180 | - |
|
181 | - if ($phpcsFile->getFixableCount() > 0) { |
|
182 | - // Attempt to fix the errors. |
|
183 | - $phpcsFile->fixer->fixFile(); |
|
184 | - $fixable = $phpcsFile->getFixableCount(); |
|
185 | - if ($fixable > 0) { |
|
186 | - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; |
|
187 | - } |
|
188 | - |
|
189 | - // Check for a .fixed file to check for accuracy of fixes. |
|
190 | - $fixedFile = $testFile.'.fixed'; |
|
191 | - if (file_exists($fixedFile) === true) { |
|
192 | - $diff = $phpcsFile->fixer->generateDiff($fixedFile); |
|
193 | - if (trim($diff) !== '') { |
|
194 | - $filename = basename($testFile); |
|
195 | - $fixedFilename = basename($fixedFile); |
|
196 | - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - // Restore the config. |
|
202 | - $config->setSettings($oldConfig); |
|
203 | - }//end foreach |
|
204 | - |
|
205 | - if (empty($failureMessages) === false) { |
|
206 | - $this->fail(implode(PHP_EOL, $failureMessages)); |
|
207 | - } |
|
208 | - |
|
209 | - }//end testSniff() |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Generate a list of test failures for a given sniffed file. |
|
214 | - * |
|
215 | - * @param \PHP_CodeSniffer\Files\LocalFile $file The file being tested. |
|
216 | - * |
|
217 | - * @return array |
|
218 | - * @throws \PHP_CodeSniffer\Exceptions\RuntimeException |
|
219 | - */ |
|
220 | - public function generateFailureMessages(LocalFile $file) |
|
221 | - { |
|
222 | - $testFile = $file->getFilename(); |
|
223 | - |
|
224 | - $foundErrors = $file->getErrors(); |
|
225 | - $foundWarnings = $file->getWarnings(); |
|
226 | - $expectedErrors = $this->getErrorList(basename($testFile)); |
|
227 | - $expectedWarnings = $this->getWarningList(basename($testFile)); |
|
228 | - |
|
229 | - if (is_array($expectedErrors) === false) { |
|
230 | - throw new RuntimeException('getErrorList() must return an array'); |
|
231 | - } |
|
232 | - |
|
233 | - if (is_array($expectedWarnings) === false) { |
|
234 | - throw new RuntimeException('getWarningList() must return an array'); |
|
235 | - } |
|
236 | - |
|
237 | - /* |
|
26 | + /** |
|
27 | + * Enable or disable the backup and restoration of the $GLOBALS array. |
|
28 | + * Overwrite this attribute in a child class of TestCase. |
|
29 | + * Setting this attribute in setUp() has no effect! |
|
30 | + * |
|
31 | + * @var boolean |
|
32 | + */ |
|
33 | + protected $backupGlobals = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * The path to the standard's main directory. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $standardsDir = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * The path to the standard's test directory. |
|
44 | + * |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + public $testsDir = null; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Sets up this unit test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + protected function setUp() |
|
56 | + { |
|
57 | + $class = get_class($this); |
|
58 | + $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; |
|
59 | + $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; |
|
60 | + |
|
61 | + }//end setUp() |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Get a list of all test files to check. |
|
66 | + * |
|
67 | + * These will have the same base as the sniff name but different extensions. |
|
68 | + * We ignore the .php file as it is the class. |
|
69 | + * |
|
70 | + * @param string $testFileBase The base path that the unit tests files will have. |
|
71 | + * |
|
72 | + * @return string[] |
|
73 | + */ |
|
74 | + protected function getTestFiles($testFileBase) |
|
75 | + { |
|
76 | + $testFiles = []; |
|
77 | + |
|
78 | + $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); |
|
79 | + $di = new \DirectoryIterator($dir); |
|
80 | + |
|
81 | + foreach ($di as $file) { |
|
82 | + $path = $file->getPathname(); |
|
83 | + if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { |
|
84 | + if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' && substr($path, -4) !== '.bak') { |
|
85 | + $testFiles[] = $path; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + // Put them in order. |
|
91 | + sort($testFiles); |
|
92 | + |
|
93 | + return $testFiles; |
|
94 | + |
|
95 | + }//end getTestFiles() |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Should this test be skipped for some reason. |
|
100 | + * |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + protected function shouldSkipTest() |
|
104 | + { |
|
105 | + return false; |
|
106 | + |
|
107 | + }//end shouldSkipTest() |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Tests the extending classes Sniff class. |
|
112 | + * |
|
113 | + * @return void |
|
114 | + * @throws \PHPUnit\Framework\Exception |
|
115 | + */ |
|
116 | + final public function testSniff() |
|
117 | + { |
|
118 | + // Skip this test if we can't run in this environment. |
|
119 | + if ($this->shouldSkipTest() === true) { |
|
120 | + $this->markTestSkipped(); |
|
121 | + } |
|
122 | + |
|
123 | + $sniffCode = Common::getSniffCode(get_class($this)); |
|
124 | + list($standardName, $categoryName, $sniffName) = explode('.', $sniffCode); |
|
125 | + |
|
126 | + $testFileBase = $this->testsDir.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; |
|
127 | + |
|
128 | + // Get a list of all test files to check. |
|
129 | + $testFiles = $this->getTestFiles($testFileBase); |
|
130 | + $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'][] = $testFiles; |
|
131 | + |
|
132 | + if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG']) === true) { |
|
133 | + $config = $GLOBALS['PHP_CODESNIFFER_CONFIG']; |
|
134 | + } else { |
|
135 | + $config = new Config(); |
|
136 | + $config->cache = false; |
|
137 | + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; |
|
138 | + } |
|
139 | + |
|
140 | + $config->standards = [$standardName]; |
|
141 | + $config->sniffs = [$sniffCode]; |
|
142 | + $config->ignored = []; |
|
143 | + |
|
144 | + if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS']) === false) { |
|
145 | + $GLOBALS['PHP_CODESNIFFER_RULESETS'] = []; |
|
146 | + } |
|
147 | + |
|
148 | + if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]) === false) { |
|
149 | + $ruleset = new Ruleset($config); |
|
150 | + $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName] = $ruleset; |
|
151 | + } |
|
152 | + |
|
153 | + $ruleset = $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]; |
|
154 | + |
|
155 | + $sniffFile = $this->standardsDir.DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'Sniff.php'; |
|
156 | + |
|
157 | + $sniffClassName = substr(get_class($this), 0, -8).'Sniff'; |
|
158 | + $sniffClassName = str_replace('\Tests\\', '\Sniffs\\', $sniffClassName); |
|
159 | + $sniffClassName = Common::cleanSniffClass($sniffClassName); |
|
160 | + |
|
161 | + $restrictions = [strtolower($sniffClassName) => true]; |
|
162 | + $ruleset->registerSniffs([$sniffFile], $restrictions, []); |
|
163 | + $ruleset->populateTokenListeners(); |
|
164 | + |
|
165 | + $failureMessages = []; |
|
166 | + foreach ($testFiles as $testFile) { |
|
167 | + $filename = basename($testFile); |
|
168 | + $oldConfig = $config->getSettings(); |
|
169 | + |
|
170 | + try { |
|
171 | + $this->setCliValues($filename, $config); |
|
172 | + $phpcsFile = new LocalFile($testFile, $ruleset, $config); |
|
173 | + $phpcsFile->process(); |
|
174 | + } catch (RuntimeException $e) { |
|
175 | + $this->fail('An unexpected exception has been caught: '.$e->getMessage()); |
|
176 | + } |
|
177 | + |
|
178 | + $failures = $this->generateFailureMessages($phpcsFile); |
|
179 | + $failureMessages = array_merge($failureMessages, $failures); |
|
180 | + |
|
181 | + if ($phpcsFile->getFixableCount() > 0) { |
|
182 | + // Attempt to fix the errors. |
|
183 | + $phpcsFile->fixer->fixFile(); |
|
184 | + $fixable = $phpcsFile->getFixableCount(); |
|
185 | + if ($fixable > 0) { |
|
186 | + $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; |
|
187 | + } |
|
188 | + |
|
189 | + // Check for a .fixed file to check for accuracy of fixes. |
|
190 | + $fixedFile = $testFile.'.fixed'; |
|
191 | + if (file_exists($fixedFile) === true) { |
|
192 | + $diff = $phpcsFile->fixer->generateDiff($fixedFile); |
|
193 | + if (trim($diff) !== '') { |
|
194 | + $filename = basename($testFile); |
|
195 | + $fixedFilename = basename($fixedFile); |
|
196 | + $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + // Restore the config. |
|
202 | + $config->setSettings($oldConfig); |
|
203 | + }//end foreach |
|
204 | + |
|
205 | + if (empty($failureMessages) === false) { |
|
206 | + $this->fail(implode(PHP_EOL, $failureMessages)); |
|
207 | + } |
|
208 | + |
|
209 | + }//end testSniff() |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Generate a list of test failures for a given sniffed file. |
|
214 | + * |
|
215 | + * @param \PHP_CodeSniffer\Files\LocalFile $file The file being tested. |
|
216 | + * |
|
217 | + * @return array |
|
218 | + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException |
|
219 | + */ |
|
220 | + public function generateFailureMessages(LocalFile $file) |
|
221 | + { |
|
222 | + $testFile = $file->getFilename(); |
|
223 | + |
|
224 | + $foundErrors = $file->getErrors(); |
|
225 | + $foundWarnings = $file->getWarnings(); |
|
226 | + $expectedErrors = $this->getErrorList(basename($testFile)); |
|
227 | + $expectedWarnings = $this->getWarningList(basename($testFile)); |
|
228 | + |
|
229 | + if (is_array($expectedErrors) === false) { |
|
230 | + throw new RuntimeException('getErrorList() must return an array'); |
|
231 | + } |
|
232 | + |
|
233 | + if (is_array($expectedWarnings) === false) { |
|
234 | + throw new RuntimeException('getWarningList() must return an array'); |
|
235 | + } |
|
236 | + |
|
237 | + /* |
|
238 | 238 | We merge errors and warnings together to make it easier |
239 | 239 | to iterate over them and produce the errors string. In this way, |
240 | 240 | we can report on errors and warnings in the same line even though |
241 | 241 | it's not really structured to allow that. |
242 | 242 | */ |
243 | 243 | |
244 | - $allProblems = []; |
|
245 | - $failureMessages = []; |
|
246 | - |
|
247 | - foreach ($foundErrors as $line => $lineErrors) { |
|
248 | - foreach ($lineErrors as $column => $errors) { |
|
249 | - if (isset($allProblems[$line]) === false) { |
|
250 | - $allProblems[$line] = [ |
|
251 | - 'expected_errors' => 0, |
|
252 | - 'expected_warnings' => 0, |
|
253 | - 'found_errors' => [], |
|
254 | - 'found_warnings' => [], |
|
255 | - ]; |
|
256 | - } |
|
257 | - |
|
258 | - $foundErrorsTemp = []; |
|
259 | - foreach ($allProblems[$line]['found_errors'] as $foundError) { |
|
260 | - $foundErrorsTemp[] = $foundError; |
|
261 | - } |
|
262 | - |
|
263 | - $errorsTemp = []; |
|
264 | - foreach ($errors as $foundError) { |
|
265 | - $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; |
|
266 | - |
|
267 | - $source = $foundError['source']; |
|
268 | - if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'], true) === false) { |
|
269 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; |
|
270 | - } |
|
271 | - |
|
272 | - if ($foundError['fixable'] === true |
|
273 | - && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'], true) === false |
|
274 | - ) { |
|
275 | - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); |
|
280 | - }//end foreach |
|
281 | - |
|
282 | - if (isset($expectedErrors[$line]) === true) { |
|
283 | - $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; |
|
284 | - } else { |
|
285 | - $allProblems[$line]['expected_errors'] = 0; |
|
286 | - } |
|
287 | - |
|
288 | - unset($expectedErrors[$line]); |
|
289 | - }//end foreach |
|
290 | - |
|
291 | - foreach ($expectedErrors as $line => $numErrors) { |
|
292 | - if (isset($allProblems[$line]) === false) { |
|
293 | - $allProblems[$line] = [ |
|
294 | - 'expected_errors' => 0, |
|
295 | - 'expected_warnings' => 0, |
|
296 | - 'found_errors' => [], |
|
297 | - 'found_warnings' => [], |
|
298 | - ]; |
|
299 | - } |
|
300 | - |
|
301 | - $allProblems[$line]['expected_errors'] = $numErrors; |
|
302 | - } |
|
303 | - |
|
304 | - foreach ($foundWarnings as $line => $lineWarnings) { |
|
305 | - foreach ($lineWarnings as $column => $warnings) { |
|
306 | - if (isset($allProblems[$line]) === false) { |
|
307 | - $allProblems[$line] = [ |
|
308 | - 'expected_errors' => 0, |
|
309 | - 'expected_warnings' => 0, |
|
310 | - 'found_errors' => [], |
|
311 | - 'found_warnings' => [], |
|
312 | - ]; |
|
313 | - } |
|
314 | - |
|
315 | - $foundWarningsTemp = []; |
|
316 | - foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { |
|
317 | - $foundWarningsTemp[] = $foundWarning; |
|
318 | - } |
|
319 | - |
|
320 | - $warningsTemp = []; |
|
321 | - foreach ($warnings as $warning) { |
|
322 | - $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; |
|
323 | - } |
|
324 | - |
|
325 | - $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); |
|
326 | - }//end foreach |
|
327 | - |
|
328 | - if (isset($expectedWarnings[$line]) === true) { |
|
329 | - $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; |
|
330 | - } else { |
|
331 | - $allProblems[$line]['expected_warnings'] = 0; |
|
332 | - } |
|
333 | - |
|
334 | - unset($expectedWarnings[$line]); |
|
335 | - }//end foreach |
|
336 | - |
|
337 | - foreach ($expectedWarnings as $line => $numWarnings) { |
|
338 | - if (isset($allProblems[$line]) === false) { |
|
339 | - $allProblems[$line] = [ |
|
340 | - 'expected_errors' => 0, |
|
341 | - 'expected_warnings' => 0, |
|
342 | - 'found_errors' => [], |
|
343 | - 'found_warnings' => [], |
|
344 | - ]; |
|
345 | - } |
|
346 | - |
|
347 | - $allProblems[$line]['expected_warnings'] = $numWarnings; |
|
348 | - } |
|
349 | - |
|
350 | - // Order the messages by line number. |
|
351 | - ksort($allProblems); |
|
352 | - |
|
353 | - foreach ($allProblems as $line => $problems) { |
|
354 | - $numErrors = count($problems['found_errors']); |
|
355 | - $numWarnings = count($problems['found_warnings']); |
|
356 | - $expectedErrors = $problems['expected_errors']; |
|
357 | - $expectedWarnings = $problems['expected_warnings']; |
|
358 | - |
|
359 | - $errors = ''; |
|
360 | - $foundString = ''; |
|
361 | - |
|
362 | - if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { |
|
363 | - $lineMessage = "[LINE $line]"; |
|
364 | - $expectedMessage = 'Expected '; |
|
365 | - $foundMessage = 'in '.basename($testFile).' but found '; |
|
366 | - |
|
367 | - if ($expectedErrors !== $numErrors) { |
|
368 | - $expectedMessage .= "$expectedErrors error(s)"; |
|
369 | - $foundMessage .= "$numErrors error(s)"; |
|
370 | - if ($numErrors !== 0) { |
|
371 | - $foundString .= 'error(s)'; |
|
372 | - $errors .= implode(PHP_EOL.' -> ', $problems['found_errors']); |
|
373 | - } |
|
374 | - |
|
375 | - if ($expectedWarnings !== $numWarnings) { |
|
376 | - $expectedMessage .= ' and '; |
|
377 | - $foundMessage .= ' and '; |
|
378 | - if ($numWarnings !== 0) { |
|
379 | - if ($foundString !== '') { |
|
380 | - $foundString .= ' and '; |
|
381 | - } |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - if ($expectedWarnings !== $numWarnings) { |
|
387 | - $expectedMessage .= "$expectedWarnings warning(s)"; |
|
388 | - $foundMessage .= "$numWarnings warning(s)"; |
|
389 | - if ($numWarnings !== 0) { |
|
390 | - $foundString .= 'warning(s)'; |
|
391 | - if (empty($errors) === false) { |
|
392 | - $errors .= PHP_EOL.' -> '; |
|
393 | - } |
|
394 | - |
|
395 | - $errors .= implode(PHP_EOL.' -> ', $problems['found_warnings']); |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - $fullMessage = "$lineMessage $expectedMessage $foundMessage."; |
|
400 | - if ($errors !== '') { |
|
401 | - $fullMessage .= " The $foundString found were:".PHP_EOL." -> $errors"; |
|
402 | - } |
|
403 | - |
|
404 | - $failureMessages[] = $fullMessage; |
|
405 | - }//end if |
|
406 | - }//end foreach |
|
407 | - |
|
408 | - return $failureMessages; |
|
409 | - |
|
410 | - }//end generateFailureMessages() |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Get a list of CLI values to set before the file is tested. |
|
415 | - * |
|
416 | - * @param string $filename The name of the file being tested. |
|
417 | - * @param \PHP_CodeSniffer\Config $config The config data for the run. |
|
418 | - * |
|
419 | - * @return void |
|
420 | - */ |
|
421 | - public function setCliValues($filename, $config) |
|
422 | - { |
|
423 | - return; |
|
424 | - |
|
425 | - }//end setCliValues() |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * Returns the lines where errors should occur. |
|
430 | - * |
|
431 | - * The key of the array should represent the line number and the value |
|
432 | - * should represent the number of errors that should occur on that line. |
|
433 | - * |
|
434 | - * @return array<int, int> |
|
435 | - */ |
|
436 | - abstract protected function getErrorList(); |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Returns the lines where warnings should occur. |
|
441 | - * |
|
442 | - * The key of the array should represent the line number and the value |
|
443 | - * should represent the number of warnings that should occur on that line. |
|
444 | - * |
|
445 | - * @return array<int, int> |
|
446 | - */ |
|
447 | - abstract protected function getWarningList(); |
|
244 | + $allProblems = []; |
|
245 | + $failureMessages = []; |
|
246 | + |
|
247 | + foreach ($foundErrors as $line => $lineErrors) { |
|
248 | + foreach ($lineErrors as $column => $errors) { |
|
249 | + if (isset($allProblems[$line]) === false) { |
|
250 | + $allProblems[$line] = [ |
|
251 | + 'expected_errors' => 0, |
|
252 | + 'expected_warnings' => 0, |
|
253 | + 'found_errors' => [], |
|
254 | + 'found_warnings' => [], |
|
255 | + ]; |
|
256 | + } |
|
257 | + |
|
258 | + $foundErrorsTemp = []; |
|
259 | + foreach ($allProblems[$line]['found_errors'] as $foundError) { |
|
260 | + $foundErrorsTemp[] = $foundError; |
|
261 | + } |
|
262 | + |
|
263 | + $errorsTemp = []; |
|
264 | + foreach ($errors as $foundError) { |
|
265 | + $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; |
|
266 | + |
|
267 | + $source = $foundError['source']; |
|
268 | + if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'], true) === false) { |
|
269 | + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; |
|
270 | + } |
|
271 | + |
|
272 | + if ($foundError['fixable'] === true |
|
273 | + && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'], true) === false |
|
274 | + ) { |
|
275 | + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); |
|
280 | + }//end foreach |
|
281 | + |
|
282 | + if (isset($expectedErrors[$line]) === true) { |
|
283 | + $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; |
|
284 | + } else { |
|
285 | + $allProblems[$line]['expected_errors'] = 0; |
|
286 | + } |
|
287 | + |
|
288 | + unset($expectedErrors[$line]); |
|
289 | + }//end foreach |
|
290 | + |
|
291 | + foreach ($expectedErrors as $line => $numErrors) { |
|
292 | + if (isset($allProblems[$line]) === false) { |
|
293 | + $allProblems[$line] = [ |
|
294 | + 'expected_errors' => 0, |
|
295 | + 'expected_warnings' => 0, |
|
296 | + 'found_errors' => [], |
|
297 | + 'found_warnings' => [], |
|
298 | + ]; |
|
299 | + } |
|
300 | + |
|
301 | + $allProblems[$line]['expected_errors'] = $numErrors; |
|
302 | + } |
|
303 | + |
|
304 | + foreach ($foundWarnings as $line => $lineWarnings) { |
|
305 | + foreach ($lineWarnings as $column => $warnings) { |
|
306 | + if (isset($allProblems[$line]) === false) { |
|
307 | + $allProblems[$line] = [ |
|
308 | + 'expected_errors' => 0, |
|
309 | + 'expected_warnings' => 0, |
|
310 | + 'found_errors' => [], |
|
311 | + 'found_warnings' => [], |
|
312 | + ]; |
|
313 | + } |
|
314 | + |
|
315 | + $foundWarningsTemp = []; |
|
316 | + foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { |
|
317 | + $foundWarningsTemp[] = $foundWarning; |
|
318 | + } |
|
319 | + |
|
320 | + $warningsTemp = []; |
|
321 | + foreach ($warnings as $warning) { |
|
322 | + $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; |
|
323 | + } |
|
324 | + |
|
325 | + $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); |
|
326 | + }//end foreach |
|
327 | + |
|
328 | + if (isset($expectedWarnings[$line]) === true) { |
|
329 | + $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; |
|
330 | + } else { |
|
331 | + $allProblems[$line]['expected_warnings'] = 0; |
|
332 | + } |
|
333 | + |
|
334 | + unset($expectedWarnings[$line]); |
|
335 | + }//end foreach |
|
336 | + |
|
337 | + foreach ($expectedWarnings as $line => $numWarnings) { |
|
338 | + if (isset($allProblems[$line]) === false) { |
|
339 | + $allProblems[$line] = [ |
|
340 | + 'expected_errors' => 0, |
|
341 | + 'expected_warnings' => 0, |
|
342 | + 'found_errors' => [], |
|
343 | + 'found_warnings' => [], |
|
344 | + ]; |
|
345 | + } |
|
346 | + |
|
347 | + $allProblems[$line]['expected_warnings'] = $numWarnings; |
|
348 | + } |
|
349 | + |
|
350 | + // Order the messages by line number. |
|
351 | + ksort($allProblems); |
|
352 | + |
|
353 | + foreach ($allProblems as $line => $problems) { |
|
354 | + $numErrors = count($problems['found_errors']); |
|
355 | + $numWarnings = count($problems['found_warnings']); |
|
356 | + $expectedErrors = $problems['expected_errors']; |
|
357 | + $expectedWarnings = $problems['expected_warnings']; |
|
358 | + |
|
359 | + $errors = ''; |
|
360 | + $foundString = ''; |
|
361 | + |
|
362 | + if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { |
|
363 | + $lineMessage = "[LINE $line]"; |
|
364 | + $expectedMessage = 'Expected '; |
|
365 | + $foundMessage = 'in '.basename($testFile).' but found '; |
|
366 | + |
|
367 | + if ($expectedErrors !== $numErrors) { |
|
368 | + $expectedMessage .= "$expectedErrors error(s)"; |
|
369 | + $foundMessage .= "$numErrors error(s)"; |
|
370 | + if ($numErrors !== 0) { |
|
371 | + $foundString .= 'error(s)'; |
|
372 | + $errors .= implode(PHP_EOL.' -> ', $problems['found_errors']); |
|
373 | + } |
|
374 | + |
|
375 | + if ($expectedWarnings !== $numWarnings) { |
|
376 | + $expectedMessage .= ' and '; |
|
377 | + $foundMessage .= ' and '; |
|
378 | + if ($numWarnings !== 0) { |
|
379 | + if ($foundString !== '') { |
|
380 | + $foundString .= ' and '; |
|
381 | + } |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + if ($expectedWarnings !== $numWarnings) { |
|
387 | + $expectedMessage .= "$expectedWarnings warning(s)"; |
|
388 | + $foundMessage .= "$numWarnings warning(s)"; |
|
389 | + if ($numWarnings !== 0) { |
|
390 | + $foundString .= 'warning(s)'; |
|
391 | + if (empty($errors) === false) { |
|
392 | + $errors .= PHP_EOL.' -> '; |
|
393 | + } |
|
394 | + |
|
395 | + $errors .= implode(PHP_EOL.' -> ', $problems['found_warnings']); |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + $fullMessage = "$lineMessage $expectedMessage $foundMessage."; |
|
400 | + if ($errors !== '') { |
|
401 | + $fullMessage .= " The $foundString found were:".PHP_EOL." -> $errors"; |
|
402 | + } |
|
403 | + |
|
404 | + $failureMessages[] = $fullMessage; |
|
405 | + }//end if |
|
406 | + }//end foreach |
|
407 | + |
|
408 | + return $failureMessages; |
|
409 | + |
|
410 | + }//end generateFailureMessages() |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Get a list of CLI values to set before the file is tested. |
|
415 | + * |
|
416 | + * @param string $filename The name of the file being tested. |
|
417 | + * @param \PHP_CodeSniffer\Config $config The config data for the run. |
|
418 | + * |
|
419 | + * @return void |
|
420 | + */ |
|
421 | + public function setCliValues($filename, $config) |
|
422 | + { |
|
423 | + return; |
|
424 | + |
|
425 | + }//end setCliValues() |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * Returns the lines where errors should occur. |
|
430 | + * |
|
431 | + * The key of the array should represent the line number and the value |
|
432 | + * should represent the number of errors that should occur on that line. |
|
433 | + * |
|
434 | + * @return array<int, int> |
|
435 | + */ |
|
436 | + abstract protected function getErrorList(); |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Returns the lines where warnings should occur. |
|
441 | + * |
|
442 | + * The key of the array should represent the line number and the value |
|
443 | + * should represent the number of warnings that should occur on that line. |
|
444 | + * |
|
445 | + * @return array<int, int> |
|
446 | + */ |
|
447 | + abstract protected function getWarningList(); |
|
448 | 448 | |
449 | 449 | |
450 | 450 | }//end class |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | */ |
55 | 55 | protected function setUp() |
56 | 56 | { |
57 | - $class = get_class($this); |
|
58 | - $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; |
|
59 | - $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; |
|
57 | + $class = get_class( $this ); |
|
58 | + $this->standardsDir = $GLOBALS[ 'PHP_CODESNIFFER_STANDARD_DIRS' ][ $class ]; |
|
59 | + $this->testsDir = $GLOBALS[ 'PHP_CODESNIFFER_TEST_DIRS' ][ $class ]; |
|
60 | 60 | |
61 | 61 | }//end setUp() |
62 | 62 | |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string[] |
73 | 73 | */ |
74 | - protected function getTestFiles($testFileBase) |
|
74 | + protected function getTestFiles( $testFileBase ) |
|
75 | 75 | { |
76 | - $testFiles = []; |
|
76 | + $testFiles = [ ]; |
|
77 | 77 | |
78 | - $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); |
|
79 | - $di = new \DirectoryIterator($dir); |
|
78 | + $dir = substr( $testFileBase, 0, strrpos( $testFileBase, DIRECTORY_SEPARATOR ) ); |
|
79 | + $di = new \DirectoryIterator( $dir ); |
|
80 | 80 | |
81 | - foreach ($di as $file) { |
|
81 | + foreach ( $di as $file ) { |
|
82 | 82 | $path = $file->getPathname(); |
83 | - if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { |
|
84 | - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' && substr($path, -4) !== '.bak') { |
|
85 | - $testFiles[] = $path; |
|
83 | + if ( substr( $path, 0, strlen( $testFileBase ) ) === $testFileBase ) { |
|
84 | + if ( $path !== $testFileBase . 'php' && substr( $path, -5 ) !== 'fixed' && substr( $path, -4 ) !== '.bak' ) { |
|
85 | + $testFiles[ ] = $path; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Put them in order. |
91 | - sort($testFiles); |
|
91 | + sort( $testFiles ); |
|
92 | 92 | |
93 | 93 | return $testFiles; |
94 | 94 | |
@@ -116,94 +116,94 @@ discard block |
||
116 | 116 | final public function testSniff() |
117 | 117 | { |
118 | 118 | // Skip this test if we can't run in this environment. |
119 | - if ($this->shouldSkipTest() === true) { |
|
119 | + if ( $this->shouldSkipTest() === true ) { |
|
120 | 120 | $this->markTestSkipped(); |
121 | 121 | } |
122 | 122 | |
123 | - $sniffCode = Common::getSniffCode(get_class($this)); |
|
124 | - list($standardName, $categoryName, $sniffName) = explode('.', $sniffCode); |
|
123 | + $sniffCode = Common::getSniffCode( get_class( $this ) ); |
|
124 | + list( $standardName, $categoryName, $sniffName ) = explode( '.', $sniffCode ); |
|
125 | 125 | |
126 | - $testFileBase = $this->testsDir.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; |
|
126 | + $testFileBase = $this->testsDir . $categoryName . DIRECTORY_SEPARATOR . $sniffName . 'UnitTest.'; |
|
127 | 127 | |
128 | 128 | // Get a list of all test files to check. |
129 | - $testFiles = $this->getTestFiles($testFileBase); |
|
130 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'][] = $testFiles; |
|
129 | + $testFiles = $this->getTestFiles( $testFileBase ); |
|
130 | + $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CASE_FILES' ][ ] = $testFiles; |
|
131 | 131 | |
132 | - if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG']) === true) { |
|
133 | - $config = $GLOBALS['PHP_CODESNIFFER_CONFIG']; |
|
132 | + if ( isset( $GLOBALS[ 'PHP_CODESNIFFER_CONFIG' ] ) === true ) { |
|
133 | + $config = $GLOBALS[ 'PHP_CODESNIFFER_CONFIG' ]; |
|
134 | 134 | } else { |
135 | 135 | $config = new Config(); |
136 | 136 | $config->cache = false; |
137 | - $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; |
|
137 | + $GLOBALS[ 'PHP_CODESNIFFER_CONFIG' ] = $config; |
|
138 | 138 | } |
139 | 139 | |
140 | - $config->standards = [$standardName]; |
|
141 | - $config->sniffs = [$sniffCode]; |
|
142 | - $config->ignored = []; |
|
140 | + $config->standards = [ $standardName ]; |
|
141 | + $config->sniffs = [ $sniffCode ]; |
|
142 | + $config->ignored = [ ]; |
|
143 | 143 | |
144 | - if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS']) === false) { |
|
145 | - $GLOBALS['PHP_CODESNIFFER_RULESETS'] = []; |
|
144 | + if ( isset( $GLOBALS[ 'PHP_CODESNIFFER_RULESETS' ] ) === false ) { |
|
145 | + $GLOBALS[ 'PHP_CODESNIFFER_RULESETS' ] = [ ]; |
|
146 | 146 | } |
147 | 147 | |
148 | - if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]) === false) { |
|
149 | - $ruleset = new Ruleset($config); |
|
150 | - $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName] = $ruleset; |
|
148 | + if ( isset( $GLOBALS[ 'PHP_CODESNIFFER_RULESETS' ][ $standardName ] ) === false ) { |
|
149 | + $ruleset = new Ruleset( $config ); |
|
150 | + $GLOBALS[ 'PHP_CODESNIFFER_RULESETS' ][ $standardName ] = $ruleset; |
|
151 | 151 | } |
152 | 152 | |
153 | - $ruleset = $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]; |
|
153 | + $ruleset = $GLOBALS[ 'PHP_CODESNIFFER_RULESETS' ][ $standardName ]; |
|
154 | 154 | |
155 | - $sniffFile = $this->standardsDir.DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'Sniff.php'; |
|
155 | + $sniffFile = $this->standardsDir . DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR . $categoryName . DIRECTORY_SEPARATOR . $sniffName . 'Sniff.php'; |
|
156 | 156 | |
157 | - $sniffClassName = substr(get_class($this), 0, -8).'Sniff'; |
|
158 | - $sniffClassName = str_replace('\Tests\\', '\Sniffs\\', $sniffClassName); |
|
159 | - $sniffClassName = Common::cleanSniffClass($sniffClassName); |
|
157 | + $sniffClassName = substr( get_class( $this ), 0, -8 ) . 'Sniff'; |
|
158 | + $sniffClassName = str_replace( '\Tests\\', '\Sniffs\\', $sniffClassName ); |
|
159 | + $sniffClassName = Common::cleanSniffClass( $sniffClassName ); |
|
160 | 160 | |
161 | - $restrictions = [strtolower($sniffClassName) => true]; |
|
162 | - $ruleset->registerSniffs([$sniffFile], $restrictions, []); |
|
161 | + $restrictions = [ strtolower( $sniffClassName ) => true ]; |
|
162 | + $ruleset->registerSniffs( [ $sniffFile ], $restrictions, [ ] ); |
|
163 | 163 | $ruleset->populateTokenListeners(); |
164 | 164 | |
165 | - $failureMessages = []; |
|
166 | - foreach ($testFiles as $testFile) { |
|
167 | - $filename = basename($testFile); |
|
165 | + $failureMessages = [ ]; |
|
166 | + foreach ( $testFiles as $testFile ) { |
|
167 | + $filename = basename( $testFile ); |
|
168 | 168 | $oldConfig = $config->getSettings(); |
169 | 169 | |
170 | 170 | try { |
171 | - $this->setCliValues($filename, $config); |
|
172 | - $phpcsFile = new LocalFile($testFile, $ruleset, $config); |
|
171 | + $this->setCliValues( $filename, $config ); |
|
172 | + $phpcsFile = new LocalFile( $testFile, $ruleset, $config ); |
|
173 | 173 | $phpcsFile->process(); |
174 | - } catch (RuntimeException $e) { |
|
175 | - $this->fail('An unexpected exception has been caught: '.$e->getMessage()); |
|
174 | + } catch ( RuntimeException $e ) { |
|
175 | + $this->fail( 'An unexpected exception has been caught: ' . $e->getMessage() ); |
|
176 | 176 | } |
177 | 177 | |
178 | - $failures = $this->generateFailureMessages($phpcsFile); |
|
179 | - $failureMessages = array_merge($failureMessages, $failures); |
|
178 | + $failures = $this->generateFailureMessages( $phpcsFile ); |
|
179 | + $failureMessages = array_merge( $failureMessages, $failures ); |
|
180 | 180 | |
181 | - if ($phpcsFile->getFixableCount() > 0) { |
|
181 | + if ( $phpcsFile->getFixableCount() > 0 ) { |
|
182 | 182 | // Attempt to fix the errors. |
183 | 183 | $phpcsFile->fixer->fixFile(); |
184 | 184 | $fixable = $phpcsFile->getFixableCount(); |
185 | - if ($fixable > 0) { |
|
186 | - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; |
|
185 | + if ( $fixable > 0 ) { |
|
186 | + $failureMessages[ ] = "Failed to fix $fixable fixable violations in $filename"; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | // Check for a .fixed file to check for accuracy of fixes. |
190 | - $fixedFile = $testFile.'.fixed'; |
|
191 | - if (file_exists($fixedFile) === true) { |
|
192 | - $diff = $phpcsFile->fixer->generateDiff($fixedFile); |
|
193 | - if (trim($diff) !== '') { |
|
194 | - $filename = basename($testFile); |
|
195 | - $fixedFilename = basename($fixedFile); |
|
196 | - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; |
|
190 | + $fixedFile = $testFile . '.fixed'; |
|
191 | + if ( file_exists( $fixedFile ) === true ) { |
|
192 | + $diff = $phpcsFile->fixer->generateDiff( $fixedFile ); |
|
193 | + if ( trim( $diff ) !== '' ) { |
|
194 | + $filename = basename( $testFile ); |
|
195 | + $fixedFilename = basename( $fixedFile ); |
|
196 | + $failureMessages[ ] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | 201 | // Restore the config. |
202 | - $config->setSettings($oldConfig); |
|
202 | + $config->setSettings( $oldConfig ); |
|
203 | 203 | }//end foreach |
204 | 204 | |
205 | - if (empty($failureMessages) === false) { |
|
206 | - $this->fail(implode(PHP_EOL, $failureMessages)); |
|
205 | + if ( empty( $failureMessages ) === false ) { |
|
206 | + $this->fail( implode( PHP_EOL, $failureMessages ) ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | }//end testSniff() |
@@ -217,21 +217,21 @@ discard block |
||
217 | 217 | * @return array |
218 | 218 | * @throws \PHP_CodeSniffer\Exceptions\RuntimeException |
219 | 219 | */ |
220 | - public function generateFailureMessages(LocalFile $file) |
|
220 | + public function generateFailureMessages( LocalFile $file ) |
|
221 | 221 | { |
222 | 222 | $testFile = $file->getFilename(); |
223 | 223 | |
224 | 224 | $foundErrors = $file->getErrors(); |
225 | 225 | $foundWarnings = $file->getWarnings(); |
226 | - $expectedErrors = $this->getErrorList(basename($testFile)); |
|
227 | - $expectedWarnings = $this->getWarningList(basename($testFile)); |
|
226 | + $expectedErrors = $this->getErrorList( basename( $testFile ) ); |
|
227 | + $expectedWarnings = $this->getWarningList( basename( $testFile ) ); |
|
228 | 228 | |
229 | - if (is_array($expectedErrors) === false) { |
|
230 | - throw new RuntimeException('getErrorList() must return an array'); |
|
229 | + if ( is_array( $expectedErrors ) === false ) { |
|
230 | + throw new RuntimeException( 'getErrorList() must return an array' ); |
|
231 | 231 | } |
232 | 232 | |
233 | - if (is_array($expectedWarnings) === false) { |
|
234 | - throw new RuntimeException('getWarningList() must return an array'); |
|
233 | + if ( is_array( $expectedWarnings ) === false ) { |
|
234 | + throw new RuntimeException( 'getWarningList() must return an array' ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /* |
@@ -241,167 +241,167 @@ discard block |
||
241 | 241 | it's not really structured to allow that. |
242 | 242 | */ |
243 | 243 | |
244 | - $allProblems = []; |
|
245 | - $failureMessages = []; |
|
244 | + $allProblems = [ ]; |
|
245 | + $failureMessages = [ ]; |
|
246 | 246 | |
247 | - foreach ($foundErrors as $line => $lineErrors) { |
|
248 | - foreach ($lineErrors as $column => $errors) { |
|
249 | - if (isset($allProblems[$line]) === false) { |
|
250 | - $allProblems[$line] = [ |
|
247 | + foreach ( $foundErrors as $line => $lineErrors ) { |
|
248 | + foreach ( $lineErrors as $column => $errors ) { |
|
249 | + if ( isset( $allProblems[ $line ] ) === false ) { |
|
250 | + $allProblems[ $line ] = [ |
|
251 | 251 | 'expected_errors' => 0, |
252 | 252 | 'expected_warnings' => 0, |
253 | - 'found_errors' => [], |
|
254 | - 'found_warnings' => [], |
|
253 | + 'found_errors' => [ ], |
|
254 | + 'found_warnings' => [ ], |
|
255 | 255 | ]; |
256 | 256 | } |
257 | 257 | |
258 | - $foundErrorsTemp = []; |
|
259 | - foreach ($allProblems[$line]['found_errors'] as $foundError) { |
|
260 | - $foundErrorsTemp[] = $foundError; |
|
258 | + $foundErrorsTemp = [ ]; |
|
259 | + foreach ( $allProblems[ $line ][ 'found_errors' ] as $foundError ) { |
|
260 | + $foundErrorsTemp[ ] = $foundError; |
|
261 | 261 | } |
262 | 262 | |
263 | - $errorsTemp = []; |
|
264 | - foreach ($errors as $foundError) { |
|
265 | - $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; |
|
263 | + $errorsTemp = [ ]; |
|
264 | + foreach ( $errors as $foundError ) { |
|
265 | + $errorsTemp[ ] = $foundError[ 'message' ] . ' (' . $foundError[ 'source' ] . ')'; |
|
266 | 266 | |
267 | - $source = $foundError['source']; |
|
268 | - if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'], true) === false) { |
|
269 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; |
|
267 | + $source = $foundError[ 'source' ]; |
|
268 | + if ( in_array( $source, $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CODES' ], true ) === false ) { |
|
269 | + $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CODES' ][ ] = $source; |
|
270 | 270 | } |
271 | 271 | |
272 | - if ($foundError['fixable'] === true |
|
273 | - && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'], true) === false |
|
272 | + if ( $foundError[ 'fixable' ] === true |
|
273 | + && in_array( $source, $GLOBALS[ 'PHP_CODESNIFFER_FIXABLE_CODES' ], true ) === false |
|
274 | 274 | ) { |
275 | - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; |
|
275 | + $GLOBALS[ 'PHP_CODESNIFFER_FIXABLE_CODES' ][ ] = $source; |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); |
|
279 | + $allProblems[ $line ][ 'found_errors' ] = array_merge( $foundErrorsTemp, $errorsTemp ); |
|
280 | 280 | }//end foreach |
281 | 281 | |
282 | - if (isset($expectedErrors[$line]) === true) { |
|
283 | - $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; |
|
282 | + if ( isset( $expectedErrors[ $line ] ) === true ) { |
|
283 | + $allProblems[ $line ][ 'expected_errors' ] = $expectedErrors[ $line ]; |
|
284 | 284 | } else { |
285 | - $allProblems[$line]['expected_errors'] = 0; |
|
285 | + $allProblems[ $line ][ 'expected_errors' ] = 0; |
|
286 | 286 | } |
287 | 287 | |
288 | - unset($expectedErrors[$line]); |
|
288 | + unset( $expectedErrors[ $line ] ); |
|
289 | 289 | }//end foreach |
290 | 290 | |
291 | - foreach ($expectedErrors as $line => $numErrors) { |
|
292 | - if (isset($allProblems[$line]) === false) { |
|
293 | - $allProblems[$line] = [ |
|
291 | + foreach ( $expectedErrors as $line => $numErrors ) { |
|
292 | + if ( isset( $allProblems[ $line ] ) === false ) { |
|
293 | + $allProblems[ $line ] = [ |
|
294 | 294 | 'expected_errors' => 0, |
295 | 295 | 'expected_warnings' => 0, |
296 | - 'found_errors' => [], |
|
297 | - 'found_warnings' => [], |
|
296 | + 'found_errors' => [ ], |
|
297 | + 'found_warnings' => [ ], |
|
298 | 298 | ]; |
299 | 299 | } |
300 | 300 | |
301 | - $allProblems[$line]['expected_errors'] = $numErrors; |
|
301 | + $allProblems[ $line ][ 'expected_errors' ] = $numErrors; |
|
302 | 302 | } |
303 | 303 | |
304 | - foreach ($foundWarnings as $line => $lineWarnings) { |
|
305 | - foreach ($lineWarnings as $column => $warnings) { |
|
306 | - if (isset($allProblems[$line]) === false) { |
|
307 | - $allProblems[$line] = [ |
|
304 | + foreach ( $foundWarnings as $line => $lineWarnings ) { |
|
305 | + foreach ( $lineWarnings as $column => $warnings ) { |
|
306 | + if ( isset( $allProblems[ $line ] ) === false ) { |
|
307 | + $allProblems[ $line ] = [ |
|
308 | 308 | 'expected_errors' => 0, |
309 | 309 | 'expected_warnings' => 0, |
310 | - 'found_errors' => [], |
|
311 | - 'found_warnings' => [], |
|
310 | + 'found_errors' => [ ], |
|
311 | + 'found_warnings' => [ ], |
|
312 | 312 | ]; |
313 | 313 | } |
314 | 314 | |
315 | - $foundWarningsTemp = []; |
|
316 | - foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { |
|
317 | - $foundWarningsTemp[] = $foundWarning; |
|
315 | + $foundWarningsTemp = [ ]; |
|
316 | + foreach ( $allProblems[ $line ][ 'found_warnings' ] as $foundWarning ) { |
|
317 | + $foundWarningsTemp[ ] = $foundWarning; |
|
318 | 318 | } |
319 | 319 | |
320 | - $warningsTemp = []; |
|
321 | - foreach ($warnings as $warning) { |
|
322 | - $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; |
|
320 | + $warningsTemp = [ ]; |
|
321 | + foreach ( $warnings as $warning ) { |
|
322 | + $warningsTemp[ ] = $warning[ 'message' ] . ' (' . $warning[ 'source' ] . ')'; |
|
323 | 323 | } |
324 | 324 | |
325 | - $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); |
|
325 | + $allProblems[ $line ][ 'found_warnings' ] = array_merge( $foundWarningsTemp, $warningsTemp ); |
|
326 | 326 | }//end foreach |
327 | 327 | |
328 | - if (isset($expectedWarnings[$line]) === true) { |
|
329 | - $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; |
|
328 | + if ( isset( $expectedWarnings[ $line ] ) === true ) { |
|
329 | + $allProblems[ $line ][ 'expected_warnings' ] = $expectedWarnings[ $line ]; |
|
330 | 330 | } else { |
331 | - $allProblems[$line]['expected_warnings'] = 0; |
|
331 | + $allProblems[ $line ][ 'expected_warnings' ] = 0; |
|
332 | 332 | } |
333 | 333 | |
334 | - unset($expectedWarnings[$line]); |
|
334 | + unset( $expectedWarnings[ $line ] ); |
|
335 | 335 | }//end foreach |
336 | 336 | |
337 | - foreach ($expectedWarnings as $line => $numWarnings) { |
|
338 | - if (isset($allProblems[$line]) === false) { |
|
339 | - $allProblems[$line] = [ |
|
337 | + foreach ( $expectedWarnings as $line => $numWarnings ) { |
|
338 | + if ( isset( $allProblems[ $line ] ) === false ) { |
|
339 | + $allProblems[ $line ] = [ |
|
340 | 340 | 'expected_errors' => 0, |
341 | 341 | 'expected_warnings' => 0, |
342 | - 'found_errors' => [], |
|
343 | - 'found_warnings' => [], |
|
342 | + 'found_errors' => [ ], |
|
343 | + 'found_warnings' => [ ], |
|
344 | 344 | ]; |
345 | 345 | } |
346 | 346 | |
347 | - $allProblems[$line]['expected_warnings'] = $numWarnings; |
|
347 | + $allProblems[ $line ][ 'expected_warnings' ] = $numWarnings; |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | // Order the messages by line number. |
351 | - ksort($allProblems); |
|
351 | + ksort( $allProblems ); |
|
352 | 352 | |
353 | - foreach ($allProblems as $line => $problems) { |
|
354 | - $numErrors = count($problems['found_errors']); |
|
355 | - $numWarnings = count($problems['found_warnings']); |
|
356 | - $expectedErrors = $problems['expected_errors']; |
|
357 | - $expectedWarnings = $problems['expected_warnings']; |
|
353 | + foreach ( $allProblems as $line => $problems ) { |
|
354 | + $numErrors = count( $problems[ 'found_errors' ] ); |
|
355 | + $numWarnings = count( $problems[ 'found_warnings' ] ); |
|
356 | + $expectedErrors = $problems[ 'expected_errors' ]; |
|
357 | + $expectedWarnings = $problems[ 'expected_warnings' ]; |
|
358 | 358 | |
359 | 359 | $errors = ''; |
360 | 360 | $foundString = ''; |
361 | 361 | |
362 | - if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { |
|
362 | + if ( $expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings ) { |
|
363 | 363 | $lineMessage = "[LINE $line]"; |
364 | 364 | $expectedMessage = 'Expected '; |
365 | - $foundMessage = 'in '.basename($testFile).' but found '; |
|
365 | + $foundMessage = 'in ' . basename( $testFile ) . ' but found '; |
|
366 | 366 | |
367 | - if ($expectedErrors !== $numErrors) { |
|
367 | + if ( $expectedErrors !== $numErrors ) { |
|
368 | 368 | $expectedMessage .= "$expectedErrors error(s)"; |
369 | 369 | $foundMessage .= "$numErrors error(s)"; |
370 | - if ($numErrors !== 0) { |
|
370 | + if ( $numErrors !== 0 ) { |
|
371 | 371 | $foundString .= 'error(s)'; |
372 | - $errors .= implode(PHP_EOL.' -> ', $problems['found_errors']); |
|
372 | + $errors .= implode( PHP_EOL . ' -> ', $problems[ 'found_errors' ] ); |
|
373 | 373 | } |
374 | 374 | |
375 | - if ($expectedWarnings !== $numWarnings) { |
|
375 | + if ( $expectedWarnings !== $numWarnings ) { |
|
376 | 376 | $expectedMessage .= ' and '; |
377 | 377 | $foundMessage .= ' and '; |
378 | - if ($numWarnings !== 0) { |
|
379 | - if ($foundString !== '') { |
|
378 | + if ( $numWarnings !== 0 ) { |
|
379 | + if ( $foundString !== '' ) { |
|
380 | 380 | $foundString .= ' and '; |
381 | 381 | } |
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if ($expectedWarnings !== $numWarnings) { |
|
386 | + if ( $expectedWarnings !== $numWarnings ) { |
|
387 | 387 | $expectedMessage .= "$expectedWarnings warning(s)"; |
388 | 388 | $foundMessage .= "$numWarnings warning(s)"; |
389 | - if ($numWarnings !== 0) { |
|
389 | + if ( $numWarnings !== 0 ) { |
|
390 | 390 | $foundString .= 'warning(s)'; |
391 | - if (empty($errors) === false) { |
|
392 | - $errors .= PHP_EOL.' -> '; |
|
391 | + if ( empty( $errors ) === false ) { |
|
392 | + $errors .= PHP_EOL . ' -> '; |
|
393 | 393 | } |
394 | 394 | |
395 | - $errors .= implode(PHP_EOL.' -> ', $problems['found_warnings']); |
|
395 | + $errors .= implode( PHP_EOL . ' -> ', $problems[ 'found_warnings' ] ); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | 399 | $fullMessage = "$lineMessage $expectedMessage $foundMessage."; |
400 | - if ($errors !== '') { |
|
401 | - $fullMessage .= " The $foundString found were:".PHP_EOL." -> $errors"; |
|
400 | + if ( $errors !== '' ) { |
|
401 | + $fullMessage .= " The $foundString found were:" . PHP_EOL . " -> $errors"; |
|
402 | 402 | } |
403 | 403 | |
404 | - $failureMessages[] = $fullMessage; |
|
404 | + $failureMessages[ ] = $fullMessage; |
|
405 | 405 | }//end if |
406 | 406 | }//end foreach |
407 | 407 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @return void |
420 | 420 | */ |
421 | - public function setCliValues($filename, $config) |
|
421 | + public function setCliValues( $filename, $config ) |
|
422 | 422 | { |
423 | 423 | return; |
424 | 424 |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | use PHP_CodeSniffer\Util\Common; |
21 | 21 | use PHPUnit\Framework\TestCase; |
22 | 22 | |
23 | -abstract class AbstractSniffUnitTest extends TestCase |
|
24 | -{ |
|
23 | +abstract class AbstractSniffUnitTest extends TestCase { |
|
25 | 24 | |
26 | 25 | /** |
27 | 26 | * Enable or disable the backup and restoration of the $GLOBALS array. |
@@ -52,8 +51,7 @@ discard block |
||
52 | 51 | * |
53 | 52 | * @return void |
54 | 53 | */ |
55 | - protected function setUp() |
|
56 | - { |
|
54 | + protected function setUp() { |
|
57 | 55 | $class = get_class($this); |
58 | 56 | $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; |
59 | 57 | $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; |
@@ -71,8 +69,7 @@ discard block |
||
71 | 69 | * |
72 | 70 | * @return string[] |
73 | 71 | */ |
74 | - protected function getTestFiles($testFileBase) |
|
75 | - { |
|
72 | + protected function getTestFiles($testFileBase) { |
|
76 | 73 | $testFiles = []; |
77 | 74 | |
78 | 75 | $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); |
@@ -100,8 +97,7 @@ discard block |
||
100 | 97 | * |
101 | 98 | * @return boolean |
102 | 99 | */ |
103 | - protected function shouldSkipTest() |
|
104 | - { |
|
100 | + protected function shouldSkipTest() { |
|
105 | 101 | return false; |
106 | 102 | |
107 | 103 | }//end shouldSkipTest() |
@@ -113,8 +109,7 @@ discard block |
||
113 | 109 | * @return void |
114 | 110 | * @throws \PHPUnit\Framework\Exception |
115 | 111 | */ |
116 | - final public function testSniff() |
|
117 | - { |
|
112 | + final public function testSniff() { |
|
118 | 113 | // Skip this test if we can't run in this environment. |
119 | 114 | if ($this->shouldSkipTest() === true) { |
120 | 115 | $this->markTestSkipped(); |
@@ -217,8 +212,7 @@ discard block |
||
217 | 212 | * @return array |
218 | 213 | * @throws \PHP_CodeSniffer\Exceptions\RuntimeException |
219 | 214 | */ |
220 | - public function generateFailureMessages(LocalFile $file) |
|
221 | - { |
|
215 | + public function generateFailureMessages(LocalFile $file) { |
|
222 | 216 | $testFile = $file->getFilename(); |
223 | 217 | |
224 | 218 | $foundErrors = $file->getErrors(); |
@@ -418,8 +412,7 @@ discard block |
||
418 | 412 | * |
419 | 413 | * @return void |
420 | 414 | */ |
421 | - public function setCliValues($filename, $config) |
|
422 | - { |
|
415 | + public function setCliValues($filename, $config) { |
|
423 | 416 | return; |
424 | 417 | |
425 | 418 | }//end setCliValues() |
@@ -18,106 +18,106 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * Prepare the test runner. |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public static function main() |
|
27 | - { |
|
28 | - TestRunner::run(self::suite()); |
|
29 | - |
|
30 | - }//end main() |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Add all sniff unit tests into a test suite. |
|
35 | - * |
|
36 | - * Sniff unit tests are found by recursing through the 'Tests' directory |
|
37 | - * of each installed coding standard. |
|
38 | - * |
|
39 | - * @return \PHPUnit\Framework\TestSuite |
|
40 | - */ |
|
41 | - public static function suite() |
|
42 | - { |
|
43 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; |
|
44 | - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; |
|
45 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'] = []; |
|
46 | - |
|
47 | - $suite = new TestSuite('PHP CodeSniffer Standards'); |
|
48 | - |
|
49 | - $isInstalled = !is_file(__DIR__.'/../../autoload.php'); |
|
50 | - |
|
51 | - // Optionally allow for ignoring the tests for one or more standards. |
|
52 | - $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); |
|
53 | - if ($ignoreTestsForStandards === false) { |
|
54 | - $ignoreTestsForStandards = []; |
|
55 | - } else { |
|
56 | - $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); |
|
57 | - } |
|
58 | - |
|
59 | - $installedStandards = self::getInstalledStandardDetails(); |
|
60 | - |
|
61 | - foreach ($installedStandards as $standard => $details) { |
|
62 | - Autoload::addSearchPath($details['path'], $details['namespace']); |
|
63 | - |
|
64 | - // If the test is running PEAR installed, the built-in standards |
|
65 | - // are split into different directories; one for the sniffs and |
|
66 | - // a different file system location for tests. |
|
67 | - if ($isInstalled === true && is_dir(dirname($details['path']).DIRECTORY_SEPARATOR.'Generic') === true) { |
|
68 | - $testPath = realpath(__DIR__.'/../../src/Standards/'.$standard); |
|
69 | - } else { |
|
70 | - $testPath = $details['path']; |
|
71 | - } |
|
72 | - |
|
73 | - if (in_array($standard, $ignoreTestsForStandards, true) === true) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - |
|
77 | - $testsDir = $testPath.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR; |
|
78 | - if (is_dir($testsDir) === false) { |
|
79 | - // No tests for this standard. |
|
80 | - continue; |
|
81 | - } |
|
82 | - |
|
83 | - $di = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($testsDir)); |
|
84 | - |
|
85 | - foreach ($di as $file) { |
|
86 | - // Skip hidden files. |
|
87 | - if (substr($file->getFilename(), 0, 1) === '.') { |
|
88 | - continue; |
|
89 | - } |
|
90 | - |
|
91 | - // Tests must have the extension 'php'. |
|
92 | - $parts = explode('.', $file); |
|
93 | - $ext = array_pop($parts); |
|
94 | - if ($ext !== 'php') { |
|
95 | - continue; |
|
96 | - } |
|
97 | - |
|
98 | - $className = Autoload::loadFile($file->getPathname()); |
|
99 | - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $details['path']; |
|
100 | - $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$className] = $testsDir; |
|
101 | - $suite->addTestSuite($className); |
|
102 | - } |
|
103 | - }//end foreach |
|
104 | - |
|
105 | - return $suite; |
|
106 | - |
|
107 | - }//end suite() |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Get the details of all coding standards installed. |
|
112 | - * |
|
113 | - * @return array |
|
114 | - * @see Standards::getInstalledStandardDetails() |
|
115 | - */ |
|
116 | - protected static function getInstalledStandardDetails() |
|
117 | - { |
|
118 | - return Standards::getInstalledStandardDetails(true); |
|
119 | - |
|
120 | - }//end getInstalledStandardDetails() |
|
21 | + /** |
|
22 | + * Prepare the test runner. |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public static function main() |
|
27 | + { |
|
28 | + TestRunner::run(self::suite()); |
|
29 | + |
|
30 | + }//end main() |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Add all sniff unit tests into a test suite. |
|
35 | + * |
|
36 | + * Sniff unit tests are found by recursing through the 'Tests' directory |
|
37 | + * of each installed coding standard. |
|
38 | + * |
|
39 | + * @return \PHPUnit\Framework\TestSuite |
|
40 | + */ |
|
41 | + public static function suite() |
|
42 | + { |
|
43 | + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; |
|
44 | + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; |
|
45 | + $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'] = []; |
|
46 | + |
|
47 | + $suite = new TestSuite('PHP CodeSniffer Standards'); |
|
48 | + |
|
49 | + $isInstalled = !is_file(__DIR__.'/../../autoload.php'); |
|
50 | + |
|
51 | + // Optionally allow for ignoring the tests for one or more standards. |
|
52 | + $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); |
|
53 | + if ($ignoreTestsForStandards === false) { |
|
54 | + $ignoreTestsForStandards = []; |
|
55 | + } else { |
|
56 | + $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); |
|
57 | + } |
|
58 | + |
|
59 | + $installedStandards = self::getInstalledStandardDetails(); |
|
60 | + |
|
61 | + foreach ($installedStandards as $standard => $details) { |
|
62 | + Autoload::addSearchPath($details['path'], $details['namespace']); |
|
63 | + |
|
64 | + // If the test is running PEAR installed, the built-in standards |
|
65 | + // are split into different directories; one for the sniffs and |
|
66 | + // a different file system location for tests. |
|
67 | + if ($isInstalled === true && is_dir(dirname($details['path']).DIRECTORY_SEPARATOR.'Generic') === true) { |
|
68 | + $testPath = realpath(__DIR__.'/../../src/Standards/'.$standard); |
|
69 | + } else { |
|
70 | + $testPath = $details['path']; |
|
71 | + } |
|
72 | + |
|
73 | + if (in_array($standard, $ignoreTestsForStandards, true) === true) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + |
|
77 | + $testsDir = $testPath.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR; |
|
78 | + if (is_dir($testsDir) === false) { |
|
79 | + // No tests for this standard. |
|
80 | + continue; |
|
81 | + } |
|
82 | + |
|
83 | + $di = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($testsDir)); |
|
84 | + |
|
85 | + foreach ($di as $file) { |
|
86 | + // Skip hidden files. |
|
87 | + if (substr($file->getFilename(), 0, 1) === '.') { |
|
88 | + continue; |
|
89 | + } |
|
90 | + |
|
91 | + // Tests must have the extension 'php'. |
|
92 | + $parts = explode('.', $file); |
|
93 | + $ext = array_pop($parts); |
|
94 | + if ($ext !== 'php') { |
|
95 | + continue; |
|
96 | + } |
|
97 | + |
|
98 | + $className = Autoload::loadFile($file->getPathname()); |
|
99 | + $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $details['path']; |
|
100 | + $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$className] = $testsDir; |
|
101 | + $suite->addTestSuite($className); |
|
102 | + } |
|
103 | + }//end foreach |
|
104 | + |
|
105 | + return $suite; |
|
106 | + |
|
107 | + }//end suite() |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Get the details of all coding standards installed. |
|
112 | + * |
|
113 | + * @return array |
|
114 | + * @see Standards::getInstalledStandardDetails() |
|
115 | + */ |
|
116 | + protected static function getInstalledStandardDetails() |
|
117 | + { |
|
118 | + return Standards::getInstalledStandardDetails(true); |
|
119 | + |
|
120 | + }//end getInstalledStandardDetails() |
|
121 | 121 | |
122 | 122 | |
123 | 123 | }//end class |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public static function main() |
27 | 27 | { |
28 | - TestRunner::run(self::suite()); |
|
28 | + TestRunner::run( self::suite() ); |
|
29 | 29 | |
30 | 30 | }//end main() |
31 | 31 | |
@@ -40,65 +40,65 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public static function suite() |
42 | 42 | { |
43 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; |
|
44 | - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; |
|
45 | - $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'] = []; |
|
43 | + $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CODES' ] = [ ]; |
|
44 | + $GLOBALS[ 'PHP_CODESNIFFER_FIXABLE_CODES' ] = [ ]; |
|
45 | + $GLOBALS[ 'PHP_CODESNIFFER_SNIFF_CASE_FILES' ] = [ ]; |
|
46 | 46 | |
47 | - $suite = new TestSuite('PHP CodeSniffer Standards'); |
|
47 | + $suite = new TestSuite( 'PHP CodeSniffer Standards' ); |
|
48 | 48 | |
49 | - $isInstalled = !is_file(__DIR__.'/../../autoload.php'); |
|
49 | + $isInstalled = ! is_file( __DIR__ . '/../../autoload.php' ); |
|
50 | 50 | |
51 | 51 | // Optionally allow for ignoring the tests for one or more standards. |
52 | - $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); |
|
53 | - if ($ignoreTestsForStandards === false) { |
|
54 | - $ignoreTestsForStandards = []; |
|
52 | + $ignoreTestsForStandards = getenv( 'PHPCS_IGNORE_TESTS' ); |
|
53 | + if ( $ignoreTestsForStandards === false ) { |
|
54 | + $ignoreTestsForStandards = [ ]; |
|
55 | 55 | } else { |
56 | - $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); |
|
56 | + $ignoreTestsForStandards = explode( ',', $ignoreTestsForStandards ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $installedStandards = self::getInstalledStandardDetails(); |
60 | 60 | |
61 | - foreach ($installedStandards as $standard => $details) { |
|
62 | - Autoload::addSearchPath($details['path'], $details['namespace']); |
|
61 | + foreach ( $installedStandards as $standard => $details ) { |
|
62 | + Autoload::addSearchPath( $details[ 'path' ], $details[ 'namespace' ] ); |
|
63 | 63 | |
64 | 64 | // If the test is running PEAR installed, the built-in standards |
65 | 65 | // are split into different directories; one for the sniffs and |
66 | 66 | // a different file system location for tests. |
67 | - if ($isInstalled === true && is_dir(dirname($details['path']).DIRECTORY_SEPARATOR.'Generic') === true) { |
|
68 | - $testPath = realpath(__DIR__.'/../../src/Standards/'.$standard); |
|
67 | + if ( $isInstalled === true && is_dir( dirname( $details[ 'path' ] ) . DIRECTORY_SEPARATOR . 'Generic' ) === true ) { |
|
68 | + $testPath = realpath( __DIR__ . '/../../src/Standards/' . $standard ); |
|
69 | 69 | } else { |
70 | - $testPath = $details['path']; |
|
70 | + $testPath = $details[ 'path' ]; |
|
71 | 71 | } |
72 | 72 | |
73 | - if (in_array($standard, $ignoreTestsForStandards, true) === true) { |
|
73 | + if ( in_array( $standard, $ignoreTestsForStandards, true ) === true ) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $testsDir = $testPath.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR; |
|
78 | - if (is_dir($testsDir) === false) { |
|
77 | + $testsDir = $testPath . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR; |
|
78 | + if ( is_dir( $testsDir ) === false ) { |
|
79 | 79 | // No tests for this standard. |
80 | 80 | continue; |
81 | 81 | } |
82 | 82 | |
83 | - $di = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($testsDir)); |
|
83 | + $di = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $testsDir ) ); |
|
84 | 84 | |
85 | - foreach ($di as $file) { |
|
85 | + foreach ( $di as $file ) { |
|
86 | 86 | // Skip hidden files. |
87 | - if (substr($file->getFilename(), 0, 1) === '.') { |
|
87 | + if ( substr( $file->getFilename(), 0, 1 ) === '.' ) { |
|
88 | 88 | continue; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Tests must have the extension 'php'. |
92 | - $parts = explode('.', $file); |
|
93 | - $ext = array_pop($parts); |
|
94 | - if ($ext !== 'php') { |
|
92 | + $parts = explode( '.', $file ); |
|
93 | + $ext = array_pop( $parts ); |
|
94 | + if ( $ext !== 'php' ) { |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $className = Autoload::loadFile($file->getPathname()); |
|
99 | - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $details['path']; |
|
100 | - $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$className] = $testsDir; |
|
101 | - $suite->addTestSuite($className); |
|
98 | + $className = Autoload::loadFile( $file->getPathname() ); |
|
99 | + $GLOBALS[ 'PHP_CODESNIFFER_STANDARD_DIRS' ][ $className ] = $details[ 'path' ]; |
|
100 | + $GLOBALS[ 'PHP_CODESNIFFER_TEST_DIRS' ][ $className ] = $testsDir; |
|
101 | + $suite->addTestSuite( $className ); |
|
102 | 102 | } |
103 | 103 | }//end foreach |
104 | 104 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected static function getInstalledStandardDetails() |
117 | 117 | { |
118 | - return Standards::getInstalledStandardDetails(true); |
|
118 | + return Standards::getInstalledStandardDetails( true ); |
|
119 | 119 | |
120 | 120 | }//end getInstalledStandardDetails() |
121 | 121 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHPUnit\TextUI\TestRunner; |
15 | 15 | use PHPUnit\Framework\TestSuite; |
16 | 16 | |
17 | -class AllSniffs |
|
18 | -{ |
|
17 | +class AllSniffs { |
|
19 | 18 | |
20 | 19 | |
21 | 20 | /** |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | * |
24 | 23 | * @return void |
25 | 24 | */ |
26 | - public static function main() |
|
27 | - { |
|
25 | + public static function main() { |
|
28 | 26 | TestRunner::run(self::suite()); |
29 | 27 | |
30 | 28 | }//end main() |
@@ -38,8 +36,7 @@ discard block |
||
38 | 36 | * |
39 | 37 | * @return \PHPUnit\Framework\TestSuite |
40 | 38 | */ |
41 | - public static function suite() |
|
42 | - { |
|
39 | + public static function suite() { |
|
43 | 40 | $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; |
44 | 41 | $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; |
45 | 42 | $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'] = []; |
@@ -113,8 +110,7 @@ discard block |
||
113 | 110 | * @return array |
114 | 111 | * @see Standards::getInstalledStandardDetails() |
115 | 112 | */ |
116 | - protected static function getInstalledStandardDetails() |
|
117 | - { |
|
113 | + protected static function getInstalledStandardDetails() { |
|
118 | 114 | return Standards::getInstalledStandardDetails(true); |
119 | 115 | |
120 | 116 | }//end getInstalledStandardDetails() |
@@ -16,120 +16,120 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Test valid public function/method names. |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function testValidNotClassFormatPublic() |
|
25 | - { |
|
26 | - $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true)); |
|
27 | - $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false)); |
|
28 | - |
|
29 | - }//end testValidNotClassFormatPublic() |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Test invalid public function/method names. |
|
34 | - * |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function testInvalidNotClassFormatPublic() |
|
38 | - { |
|
39 | - $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true)); |
|
40 | - $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true)); |
|
41 | - $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true)); |
|
42 | - |
|
43 | - $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, true, true)); |
|
44 | - $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, true, true)); |
|
45 | - $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, true, true)); |
|
46 | - |
|
47 | - $this->assertFalse(Common::isCamelCaps('this*IsCamelCaps', false, true, true)); |
|
48 | - $this->assertFalse(Common::isCamelCaps('this-IsCamelCaps', false, true, true)); |
|
49 | - $this->assertFalse(Common::isCamelCaps('this_IsCamelCaps', false, true, true)); |
|
50 | - $this->assertFalse(Common::isCamelCaps('this_is_camel_caps', false, true, true)); |
|
51 | - |
|
52 | - }//end testInvalidNotClassFormatPublic() |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Test valid private method names. |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function testValidNotClassFormatPrivate() |
|
61 | - { |
|
62 | - $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true)); |
|
63 | - $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false)); |
|
64 | - $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true)); |
|
65 | - $this->assertTrue(Common::isCamelCaps('_i18n', false, false, true)); |
|
66 | - |
|
67 | - }//end testValidNotClassFormatPrivate() |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Test invalid private method names. |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function testInvalidNotClassFormatPrivate() |
|
76 | - { |
|
77 | - $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', false, false, true)); |
|
78 | - $this->assertFalse(Common::isCamelCaps('_thisISCamelCaps', false, false, true)); |
|
79 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true)); |
|
80 | - $this->assertFalse(Common::isCamelCaps('__thisIsCamelCaps', false, false, true)); |
|
81 | - $this->assertFalse(Common::isCamelCaps('__thisISCamelCaps', false, false, false)); |
|
82 | - |
|
83 | - $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, false, true)); |
|
84 | - $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, false, true)); |
|
85 | - $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, false, true)); |
|
86 | - $this->assertFalse(Common::isCamelCaps('_this_is_camel_caps', false, false, true)); |
|
87 | - |
|
88 | - }//end testInvalidNotClassFormatPrivate() |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Test valid class names. |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function testValidClassFormatPublic() |
|
97 | - { |
|
98 | - $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true)); |
|
99 | - $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false)); |
|
100 | - $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false)); |
|
101 | - |
|
102 | - }//end testValidClassFormatPublic() |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Test invalid class names. |
|
107 | - * |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public function testInvalidClassFormat() |
|
111 | - { |
|
112 | - $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true)); |
|
113 | - $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true)); |
|
114 | - $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true)); |
|
115 | - |
|
116 | - }//end testInvalidClassFormat() |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Test invalid class names with the private flag set. |
|
121 | - * |
|
122 | - * Note that the private flag is ignored if the class format |
|
123 | - * flag is set, so these names are all invalid. |
|
124 | - * |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function testInvalidClassFormatPrivate() |
|
128 | - { |
|
129 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true)); |
|
130 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false)); |
|
131 | - |
|
132 | - }//end testInvalidClassFormatPrivate() |
|
19 | + /** |
|
20 | + * Test valid public function/method names. |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function testValidNotClassFormatPublic() |
|
25 | + { |
|
26 | + $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true)); |
|
27 | + $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false)); |
|
28 | + |
|
29 | + }//end testValidNotClassFormatPublic() |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Test invalid public function/method names. |
|
34 | + * |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function testInvalidNotClassFormatPublic() |
|
38 | + { |
|
39 | + $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true)); |
|
40 | + $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true)); |
|
41 | + $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true)); |
|
42 | + |
|
43 | + $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, true, true)); |
|
44 | + $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, true, true)); |
|
45 | + $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, true, true)); |
|
46 | + |
|
47 | + $this->assertFalse(Common::isCamelCaps('this*IsCamelCaps', false, true, true)); |
|
48 | + $this->assertFalse(Common::isCamelCaps('this-IsCamelCaps', false, true, true)); |
|
49 | + $this->assertFalse(Common::isCamelCaps('this_IsCamelCaps', false, true, true)); |
|
50 | + $this->assertFalse(Common::isCamelCaps('this_is_camel_caps', false, true, true)); |
|
51 | + |
|
52 | + }//end testInvalidNotClassFormatPublic() |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Test valid private method names. |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function testValidNotClassFormatPrivate() |
|
61 | + { |
|
62 | + $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true)); |
|
63 | + $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false)); |
|
64 | + $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true)); |
|
65 | + $this->assertTrue(Common::isCamelCaps('_i18n', false, false, true)); |
|
66 | + |
|
67 | + }//end testValidNotClassFormatPrivate() |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Test invalid private method names. |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function testInvalidNotClassFormatPrivate() |
|
76 | + { |
|
77 | + $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', false, false, true)); |
|
78 | + $this->assertFalse(Common::isCamelCaps('_thisISCamelCaps', false, false, true)); |
|
79 | + $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true)); |
|
80 | + $this->assertFalse(Common::isCamelCaps('__thisIsCamelCaps', false, false, true)); |
|
81 | + $this->assertFalse(Common::isCamelCaps('__thisISCamelCaps', false, false, false)); |
|
82 | + |
|
83 | + $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, false, true)); |
|
84 | + $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, false, true)); |
|
85 | + $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, false, true)); |
|
86 | + $this->assertFalse(Common::isCamelCaps('_this_is_camel_caps', false, false, true)); |
|
87 | + |
|
88 | + }//end testInvalidNotClassFormatPrivate() |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Test valid class names. |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function testValidClassFormatPublic() |
|
97 | + { |
|
98 | + $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true)); |
|
99 | + $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false)); |
|
100 | + $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false)); |
|
101 | + |
|
102 | + }//end testValidClassFormatPublic() |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Test invalid class names. |
|
107 | + * |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public function testInvalidClassFormat() |
|
111 | + { |
|
112 | + $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true)); |
|
113 | + $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true)); |
|
114 | + $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true)); |
|
115 | + |
|
116 | + }//end testInvalidClassFormat() |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Test invalid class names with the private flag set. |
|
121 | + * |
|
122 | + * Note that the private flag is ignored if the class format |
|
123 | + * flag is set, so these names are all invalid. |
|
124 | + * |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function testInvalidClassFormatPrivate() |
|
128 | + { |
|
129 | + $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true)); |
|
130 | + $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false)); |
|
131 | + |
|
132 | + }//end testInvalidClassFormatPrivate() |
|
133 | 133 | |
134 | 134 | |
135 | 135 | }//end class |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function testValidNotClassFormatPublic() |
25 | 25 | { |
26 | - $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true)); |
|
27 | - $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false)); |
|
26 | + $this->assertTrue( Common::isCamelCaps( 'thisIsCamelCaps', false, true, true ) ); |
|
27 | + $this->assertTrue( Common::isCamelCaps( 'thisISCamelCaps', false, true, false ) ); |
|
28 | 28 | |
29 | 29 | }//end testValidNotClassFormatPublic() |
30 | 30 | |
@@ -36,18 +36,18 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function testInvalidNotClassFormatPublic() |
38 | 38 | { |
39 | - $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true)); |
|
40 | - $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true)); |
|
41 | - $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true)); |
|
39 | + $this->assertFalse( Common::isCamelCaps( '_thisIsCamelCaps', false, true, true ) ); |
|
40 | + $this->assertFalse( Common::isCamelCaps( 'thisISCamelCaps', false, true, true ) ); |
|
41 | + $this->assertFalse( Common::isCamelCaps( 'ThisIsCamelCaps', false, true, true ) ); |
|
42 | 42 | |
43 | - $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, true, true)); |
|
44 | - $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, true, true)); |
|
45 | - $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, true, true)); |
|
43 | + $this->assertFalse( Common::isCamelCaps( '3thisIsCamelCaps', false, true, true ) ); |
|
44 | + $this->assertFalse( Common::isCamelCaps( '*thisIsCamelCaps', false, true, true ) ); |
|
45 | + $this->assertFalse( Common::isCamelCaps( '-thisIsCamelCaps', false, true, true ) ); |
|
46 | 46 | |
47 | - $this->assertFalse(Common::isCamelCaps('this*IsCamelCaps', false, true, true)); |
|
48 | - $this->assertFalse(Common::isCamelCaps('this-IsCamelCaps', false, true, true)); |
|
49 | - $this->assertFalse(Common::isCamelCaps('this_IsCamelCaps', false, true, true)); |
|
50 | - $this->assertFalse(Common::isCamelCaps('this_is_camel_caps', false, true, true)); |
|
47 | + $this->assertFalse( Common::isCamelCaps( 'this*IsCamelCaps', false, true, true ) ); |
|
48 | + $this->assertFalse( Common::isCamelCaps( 'this-IsCamelCaps', false, true, true ) ); |
|
49 | + $this->assertFalse( Common::isCamelCaps( 'this_IsCamelCaps', false, true, true ) ); |
|
50 | + $this->assertFalse( Common::isCamelCaps( 'this_is_camel_caps', false, true, true ) ); |
|
51 | 51 | |
52 | 52 | }//end testInvalidNotClassFormatPublic() |
53 | 53 | |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function testValidNotClassFormatPrivate() |
61 | 61 | { |
62 | - $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true)); |
|
63 | - $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false)); |
|
64 | - $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true)); |
|
65 | - $this->assertTrue(Common::isCamelCaps('_i18n', false, false, true)); |
|
62 | + $this->assertTrue( Common::isCamelCaps( '_thisIsCamelCaps', false, false, true ) ); |
|
63 | + $this->assertTrue( Common::isCamelCaps( '_thisISCamelCaps', false, false, false ) ); |
|
64 | + $this->assertTrue( Common::isCamelCaps( '_i18N', false, false, true ) ); |
|
65 | + $this->assertTrue( Common::isCamelCaps( '_i18n', false, false, true ) ); |
|
66 | 66 | |
67 | 67 | }//end testValidNotClassFormatPrivate() |
68 | 68 | |
@@ -74,16 +74,16 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function testInvalidNotClassFormatPrivate() |
76 | 76 | { |
77 | - $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', false, false, true)); |
|
78 | - $this->assertFalse(Common::isCamelCaps('_thisISCamelCaps', false, false, true)); |
|
79 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true)); |
|
80 | - $this->assertFalse(Common::isCamelCaps('__thisIsCamelCaps', false, false, true)); |
|
81 | - $this->assertFalse(Common::isCamelCaps('__thisISCamelCaps', false, false, false)); |
|
77 | + $this->assertFalse( Common::isCamelCaps( 'thisIsCamelCaps', false, false, true ) ); |
|
78 | + $this->assertFalse( Common::isCamelCaps( '_thisISCamelCaps', false, false, true ) ); |
|
79 | + $this->assertFalse( Common::isCamelCaps( '_ThisIsCamelCaps', false, false, true ) ); |
|
80 | + $this->assertFalse( Common::isCamelCaps( '__thisIsCamelCaps', false, false, true ) ); |
|
81 | + $this->assertFalse( Common::isCamelCaps( '__thisISCamelCaps', false, false, false ) ); |
|
82 | 82 | |
83 | - $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, false, true)); |
|
84 | - $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, false, true)); |
|
85 | - $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, false, true)); |
|
86 | - $this->assertFalse(Common::isCamelCaps('_this_is_camel_caps', false, false, true)); |
|
83 | + $this->assertFalse( Common::isCamelCaps( '3thisIsCamelCaps', false, false, true ) ); |
|
84 | + $this->assertFalse( Common::isCamelCaps( '*thisIsCamelCaps', false, false, true ) ); |
|
85 | + $this->assertFalse( Common::isCamelCaps( '-thisIsCamelCaps', false, false, true ) ); |
|
86 | + $this->assertFalse( Common::isCamelCaps( '_this_is_camel_caps', false, false, true ) ); |
|
87 | 87 | |
88 | 88 | }//end testInvalidNotClassFormatPrivate() |
89 | 89 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function testValidClassFormatPublic() |
97 | 97 | { |
98 | - $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true)); |
|
99 | - $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false)); |
|
100 | - $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false)); |
|
98 | + $this->assertTrue( Common::isCamelCaps( 'ThisIsCamelCaps', true, true, true ) ); |
|
99 | + $this->assertTrue( Common::isCamelCaps( 'ThisISCamelCaps', true, true, false ) ); |
|
100 | + $this->assertTrue( Common::isCamelCaps( 'This3IsCamelCaps', true, true, false ) ); |
|
101 | 101 | |
102 | 102 | }//end testValidClassFormatPublic() |
103 | 103 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function testInvalidClassFormat() |
111 | 111 | { |
112 | - $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true)); |
|
113 | - $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true)); |
|
114 | - $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true)); |
|
112 | + $this->assertFalse( Common::isCamelCaps( 'thisIsCamelCaps', true ) ); |
|
113 | + $this->assertFalse( Common::isCamelCaps( 'This-IsCamelCaps', true ) ); |
|
114 | + $this->assertFalse( Common::isCamelCaps( 'This_Is_Camel_Caps', true ) ); |
|
115 | 115 | |
116 | 116 | }//end testInvalidClassFormat() |
117 | 117 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function testInvalidClassFormatPrivate() |
128 | 128 | { |
129 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true)); |
|
130 | - $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false)); |
|
129 | + $this->assertFalse( Common::isCamelCaps( '_ThisIsCamelCaps', true, true ) ); |
|
130 | + $this->assertFalse( Common::isCamelCaps( '_ThisIsCamelCaps', true, false ) ); |
|
131 | 131 | |
132 | 132 | }//end testInvalidClassFormatPrivate() |
133 | 133 |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | use PHP_CodeSniffer\Util\Common; |
13 | 13 | use PHPUnit\Framework\TestCase; |
14 | 14 | |
15 | -class IsCamelCapsTest extends TestCase |
|
16 | -{ |
|
15 | +class IsCamelCapsTest extends TestCase { |
|
17 | 16 | |
18 | 17 | |
19 | 18 | /** |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * |
22 | 21 | * @return void |
23 | 22 | */ |
24 | - public function testValidNotClassFormatPublic() |
|
25 | - { |
|
23 | + public function testValidNotClassFormatPublic() { |
|
26 | 24 | $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true)); |
27 | 25 | $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false)); |
28 | 26 | |
@@ -34,8 +32,7 @@ discard block |
||
34 | 32 | * |
35 | 33 | * @return void |
36 | 34 | */ |
37 | - public function testInvalidNotClassFormatPublic() |
|
38 | - { |
|
35 | + public function testInvalidNotClassFormatPublic() { |
|
39 | 36 | $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true)); |
40 | 37 | $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true)); |
41 | 38 | $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true)); |
@@ -57,8 +54,7 @@ discard block |
||
57 | 54 | * |
58 | 55 | * @return void |
59 | 56 | */ |
60 | - public function testValidNotClassFormatPrivate() |
|
61 | - { |
|
57 | + public function testValidNotClassFormatPrivate() { |
|
62 | 58 | $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true)); |
63 | 59 | $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false)); |
64 | 60 | $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true)); |
@@ -72,8 +68,7 @@ discard block |
||
72 | 68 | * |
73 | 69 | * @return void |
74 | 70 | */ |
75 | - public function testInvalidNotClassFormatPrivate() |
|
76 | - { |
|
71 | + public function testInvalidNotClassFormatPrivate() { |
|
77 | 72 | $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', false, false, true)); |
78 | 73 | $this->assertFalse(Common::isCamelCaps('_thisISCamelCaps', false, false, true)); |
79 | 74 | $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true)); |
@@ -93,8 +88,7 @@ discard block |
||
93 | 88 | * |
94 | 89 | * @return void |
95 | 90 | */ |
96 | - public function testValidClassFormatPublic() |
|
97 | - { |
|
91 | + public function testValidClassFormatPublic() { |
|
98 | 92 | $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true)); |
99 | 93 | $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false)); |
100 | 94 | $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false)); |
@@ -107,8 +101,7 @@ discard block |
||
107 | 101 | * |
108 | 102 | * @return void |
109 | 103 | */ |
110 | - public function testInvalidClassFormat() |
|
111 | - { |
|
104 | + public function testInvalidClassFormat() { |
|
112 | 105 | $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true)); |
113 | 106 | $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true)); |
114 | 107 | $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true)); |
@@ -124,8 +117,7 @@ discard block |
||
124 | 117 | * |
125 | 118 | * @return void |
126 | 119 | */ |
127 | - public function testInvalidClassFormatPrivate() |
|
128 | - { |
|
120 | + public function testInvalidClassFormatPrivate() { |
|
129 | 121 | $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true)); |
130 | 122 | $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false)); |
131 | 123 |
@@ -18,8 +18,8 @@ |
||
18 | 18 | |
19 | 19 | /* testSwitch */ |
20 | 20 | switch ($a) { |
21 | - case 1: {break;} |
|
22 | - default: {break;} |
|
21 | + case 1: {break;} |
|
22 | + default: {break;} |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /* testStatementAsArrayValue */ |
@@ -4,25 +4,25 @@ |
||
4 | 4 | $a = false; |
5 | 5 | |
6 | 6 | /* testControlStructure */ |
7 | -while(true) {} |
|
7 | +while ( true ) {} |
|
8 | 8 | $a = 1; |
9 | 9 | |
10 | 10 | /* testClosureAssignment */ |
11 | -$a = function($b=false;){}; |
|
11 | +$a = function( $b = false; ) {}; |
|
12 | 12 | |
13 | 13 | /* testHeredocFunctionArg */ |
14 | -myFunction(<<<END |
|
14 | +myFunction( <<<END |
|
15 | 15 | Foo |
16 | 16 | END |
17 | -, 'bar'); |
|
17 | +, 'bar' ); |
|
18 | 18 | |
19 | 19 | /* testSwitch */ |
20 | -switch ($a) { |
|
21 | - case 1: {break;} |
|
22 | - default: {break;} |
|
20 | +switch ( $a ) { |
|
21 | + case 1: {break; } |
|
22 | + default: {break; } |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /* testStatementAsArrayValue */ |
26 | -$a = [new Datetime]; |
|
27 | -$a = array(new Datetime); |
|
26 | +$a = [ new Datetime ]; |
|
27 | +$a = array( new Datetime ); |
|
28 | 28 | $a = new Datetime; |
@@ -12,8 +12,8 @@ |
||
12 | 12 | |
13 | 13 | /* testHeredocFunctionArg */ |
14 | 14 | myFunction(<<<END |
15 | -Foo |
|
16 | -END |
|
15 | +foo |
|
16 | +end |
|
17 | 17 | , 'bar'); |
18 | 18 | |
19 | 19 | /* testSwitch */ |
@@ -17,187 +17,187 @@ |
||
17 | 17 | class FindEndOfStatementTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | - * |
|
23 | - * @var \PHP_CodeSniffer\Files\File |
|
24 | - */ |
|
25 | - private $phpcsFile; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | - * |
|
31 | - * Methods used for these tests can be found in a test case file in the same |
|
32 | - * directory and with the same name, using the .inc extension. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setUp() |
|
37 | - { |
|
38 | - $config = new Config(); |
|
39 | - $config->standards = ['Generic']; |
|
20 | + /** |
|
21 | + * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
|
22 | + * |
|
23 | + * @var \PHP_CodeSniffer\Files\File |
|
24 | + */ |
|
25 | + private $phpcsFile; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. |
|
30 | + * |
|
31 | + * Methods used for these tests can be found in a test case file in the same |
|
32 | + * directory and with the same name, using the .inc extension. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setUp() |
|
37 | + { |
|
38 | + $config = new Config(); |
|
39 | + $config->standards = ['Generic']; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset($config); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | - $this->phpcsFile->process(); |
|
46 | - |
|
47 | - }//end setUp() |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Clean up after finished test. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function tearDown() |
|
56 | - { |
|
57 | - unset($this->phpcsFile); |
|
58 | - |
|
59 | - }//end tearDown() |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Test a simple assignment. |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function testSimpleAssignment() |
|
68 | - { |
|
69 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSimpleAssignment */') + 2); |
|
70 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
43 | + $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | + $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
45 | + $this->phpcsFile->process(); |
|
46 | + |
|
47 | + }//end setUp() |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Clean up after finished test. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function tearDown() |
|
56 | + { |
|
57 | + unset($this->phpcsFile); |
|
58 | + |
|
59 | + }//end tearDown() |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Test a simple assignment. |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function testSimpleAssignment() |
|
68 | + { |
|
69 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSimpleAssignment */') + 2); |
|
70 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
71 | 71 | |
72 | - $tokens = $this->phpcsFile->getTokens(); |
|
73 | - $this->assertSame($tokens[($start + 5)], $tokens[$found]); |
|
72 | + $tokens = $this->phpcsFile->getTokens(); |
|
73 | + $this->assertSame($tokens[($start + 5)], $tokens[$found]); |
|
74 | 74 | |
75 | - }//end testSimpleAssignment() |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Test a direct call to a control structure. |
|
80 | - * |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function testControlStructure() |
|
84 | - { |
|
85 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testControlStructure */') + 2); |
|
86 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
87 | - |
|
88 | - $tokens = $this->phpcsFile->getTokens(); |
|
89 | - $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
90 | - |
|
91 | - }//end testControlStructure() |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Test the assignment of a closure. |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function testClosureAssignment() |
|
100 | - { |
|
101 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testClosureAssignment */') + 2); |
|
102 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
103 | - |
|
104 | - $tokens = $this->phpcsFile->getTokens(); |
|
105 | - $this->assertSame($tokens[($start + 13)], $tokens[$found]); |
|
106 | - |
|
107 | - }//end testClosureAssignment() |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Test using a heredoc in a function argument. |
|
112 | - * |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function testHeredocFunctionArg() |
|
116 | - { |
|
117 | - // Find the end of the function. |
|
118 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testHeredocFunctionArg */') + 2); |
|
119 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
120 | - |
|
121 | - $tokens = $this->phpcsFile->getTokens(); |
|
122 | - $this->assertSame($tokens[($start + 10)], $tokens[$found]); |
|
75 | + }//end testSimpleAssignment() |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Test a direct call to a control structure. |
|
80 | + * |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function testControlStructure() |
|
84 | + { |
|
85 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testControlStructure */') + 2); |
|
86 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
87 | + |
|
88 | + $tokens = $this->phpcsFile->getTokens(); |
|
89 | + $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
90 | + |
|
91 | + }//end testControlStructure() |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Test the assignment of a closure. |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function testClosureAssignment() |
|
100 | + { |
|
101 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testClosureAssignment */') + 2); |
|
102 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
103 | + |
|
104 | + $tokens = $this->phpcsFile->getTokens(); |
|
105 | + $this->assertSame($tokens[($start + 13)], $tokens[$found]); |
|
106 | + |
|
107 | + }//end testClosureAssignment() |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Test using a heredoc in a function argument. |
|
112 | + * |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function testHeredocFunctionArg() |
|
116 | + { |
|
117 | + // Find the end of the function. |
|
118 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testHeredocFunctionArg */') + 2); |
|
119 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
120 | + |
|
121 | + $tokens = $this->phpcsFile->getTokens(); |
|
122 | + $this->assertSame($tokens[($start + 10)], $tokens[$found]); |
|
123 | 123 | |
124 | - // Find the end of the heredoc. |
|
125 | - $start += 2; |
|
126 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
124 | + // Find the end of the heredoc. |
|
125 | + $start += 2; |
|
126 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
127 | 127 | |
128 | - $tokens = $this->phpcsFile->getTokens(); |
|
129 | - $this->assertSame($tokens[($start + 4)], $tokens[$found]); |
|
128 | + $tokens = $this->phpcsFile->getTokens(); |
|
129 | + $this->assertSame($tokens[($start + 4)], $tokens[$found]); |
|
130 | 130 | |
131 | - // Find the end of the last arg. |
|
132 | - $start = ($found + 2); |
|
133 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
131 | + // Find the end of the last arg. |
|
132 | + $start = ($found + 2); |
|
133 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
134 | 134 | |
135 | - $tokens = $this->phpcsFile->getTokens(); |
|
136 | - $this->assertSame($tokens[$start], $tokens[$found]); |
|
135 | + $tokens = $this->phpcsFile->getTokens(); |
|
136 | + $this->assertSame($tokens[$start], $tokens[$found]); |
|
137 | 137 | |
138 | - }//end testHeredocFunctionArg() |
|
138 | + }//end testHeredocFunctionArg() |
|
139 | 139 | |
140 | 140 | |
141 | - /** |
|
142 | - * Test parts of a switch statement. |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function testSwitch() |
|
147 | - { |
|
148 | - // Find the end of the switch. |
|
149 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSwitch */') + 2); |
|
150 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
141 | + /** |
|
142 | + * Test parts of a switch statement. |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function testSwitch() |
|
147 | + { |
|
148 | + // Find the end of the switch. |
|
149 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSwitch */') + 2); |
|
150 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
151 | 151 | |
152 | - $tokens = $this->phpcsFile->getTokens(); |
|
153 | - $this->assertSame($tokens[($start + 28)], $tokens[$found]); |
|
152 | + $tokens = $this->phpcsFile->getTokens(); |
|
153 | + $this->assertSame($tokens[($start + 28)], $tokens[$found]); |
|
154 | 154 | |
155 | - // Find the end of the case. |
|
156 | - $start += 9; |
|
157 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
155 | + // Find the end of the case. |
|
156 | + $start += 9; |
|
157 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
158 | 158 | |
159 | - $tokens = $this->phpcsFile->getTokens(); |
|
160 | - $this->assertSame($tokens[($start + 8)], $tokens[$found]); |
|
159 | + $tokens = $this->phpcsFile->getTokens(); |
|
160 | + $this->assertSame($tokens[($start + 8)], $tokens[$found]); |
|
161 | 161 | |
162 | - // Find the end of default case. |
|
163 | - $start += 11; |
|
164 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
162 | + // Find the end of default case. |
|
163 | + $start += 11; |
|
164 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
165 | 165 | |
166 | - $tokens = $this->phpcsFile->getTokens(); |
|
167 | - $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
166 | + $tokens = $this->phpcsFile->getTokens(); |
|
167 | + $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
168 | 168 | |
169 | - }//end testSwitch() |
|
169 | + }//end testSwitch() |
|
170 | 170 | |
171 | 171 | |
172 | - /** |
|
173 | - * Test statements that are array values. |
|
174 | - * |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - public function testStatementAsArrayValue() |
|
178 | - { |
|
179 | - // Test short array syntax. |
|
180 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */') + 7); |
|
181 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
172 | + /** |
|
173 | + * Test statements that are array values. |
|
174 | + * |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + public function testStatementAsArrayValue() |
|
178 | + { |
|
179 | + // Test short array syntax. |
|
180 | + $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */') + 7); |
|
181 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
182 | 182 | |
183 | - $tokens = $this->phpcsFile->getTokens(); |
|
184 | - $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
183 | + $tokens = $this->phpcsFile->getTokens(); |
|
184 | + $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
185 | 185 | |
186 | - // Test long array syntax. |
|
187 | - $start += 12; |
|
188 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
186 | + // Test long array syntax. |
|
187 | + $start += 12; |
|
188 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
189 | 189 | |
190 | - $tokens = $this->phpcsFile->getTokens(); |
|
191 | - $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
190 | + $tokens = $this->phpcsFile->getTokens(); |
|
191 | + $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
192 | 192 | |
193 | - // Test same statement outside of array. |
|
194 | - $start += 10; |
|
195 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
193 | + // Test same statement outside of array. |
|
194 | + $start += 10; |
|
195 | + $found = $this->phpcsFile->findEndOfStatement($start); |
|
196 | 196 | |
197 | - $tokens = $this->phpcsFile->getTokens(); |
|
198 | - $this->assertSame($tokens[($start + 3)], $tokens[$found]); |
|
197 | + $tokens = $this->phpcsFile->getTokens(); |
|
198 | + $this->assertSame($tokens[($start + 3)], $tokens[$found]); |
|
199 | 199 | |
200 | - }//end testStatementAsArrayValue() |
|
200 | + }//end testStatementAsArrayValue() |
|
201 | 201 | |
202 | 202 | |
203 | 203 | }//end class |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function setUp() |
37 | 37 | { |
38 | 38 | $config = new Config(); |
39 | - $config->standards = ['Generic']; |
|
39 | + $config->standards = [ 'Generic' ]; |
|
40 | 40 | |
41 | - $ruleset = new Ruleset($config); |
|
41 | + $ruleset = new Ruleset( $config ); |
|
42 | 42 | |
43 | - $pathToTestFile = dirname(__FILE__).'/'.basename(__FILE__, '.php').'.inc'; |
|
44 | - $this->phpcsFile = new DummyFile(file_get_contents($pathToTestFile), $ruleset, $config); |
|
43 | + $pathToTestFile = dirname( __FILE__ ) . '/' . basename( __FILE__, '.php' ) . '.inc'; |
|
44 | + $this->phpcsFile = new DummyFile( file_get_contents( $pathToTestFile ), $ruleset, $config ); |
|
45 | 45 | $this->phpcsFile->process(); |
46 | 46 | |
47 | 47 | }//end setUp() |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() |
56 | 56 | { |
57 | - unset($this->phpcsFile); |
|
57 | + unset( $this->phpcsFile ); |
|
58 | 58 | |
59 | 59 | }//end tearDown() |
60 | 60 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function testSimpleAssignment() |
68 | 68 | { |
69 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSimpleAssignment */') + 2); |
|
70 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
69 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testSimpleAssignment */' ) + 2 ); |
|
70 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
71 | 71 | |
72 | 72 | $tokens = $this->phpcsFile->getTokens(); |
73 | - $this->assertSame($tokens[($start + 5)], $tokens[$found]); |
|
73 | + $this->assertSame( $tokens[ ( $start + 5 ) ], $tokens[ $found ] ); |
|
74 | 74 | |
75 | 75 | }//end testSimpleAssignment() |
76 | 76 | |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function testControlStructure() |
84 | 84 | { |
85 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testControlStructure */') + 2); |
|
86 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
85 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testControlStructure */' ) + 2 ); |
|
86 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
87 | 87 | |
88 | 88 | $tokens = $this->phpcsFile->getTokens(); |
89 | - $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
89 | + $this->assertSame( $tokens[ ( $start + 6 ) ], $tokens[ $found ] ); |
|
90 | 90 | |
91 | 91 | }//end testControlStructure() |
92 | 92 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function testClosureAssignment() |
100 | 100 | { |
101 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testClosureAssignment */') + 2); |
|
102 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
101 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testClosureAssignment */' ) + 2 ); |
|
102 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
103 | 103 | |
104 | 104 | $tokens = $this->phpcsFile->getTokens(); |
105 | - $this->assertSame($tokens[($start + 13)], $tokens[$found]); |
|
105 | + $this->assertSame( $tokens[ ( $start + 13 ) ], $tokens[ $found ] ); |
|
106 | 106 | |
107 | 107 | }//end testClosureAssignment() |
108 | 108 | |
@@ -115,25 +115,25 @@ discard block |
||
115 | 115 | public function testHeredocFunctionArg() |
116 | 116 | { |
117 | 117 | // Find the end of the function. |
118 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testHeredocFunctionArg */') + 2); |
|
119 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
118 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testHeredocFunctionArg */' ) + 2 ); |
|
119 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
120 | 120 | |
121 | 121 | $tokens = $this->phpcsFile->getTokens(); |
122 | - $this->assertSame($tokens[($start + 10)], $tokens[$found]); |
|
122 | + $this->assertSame( $tokens[ ( $start + 10 ) ], $tokens[ $found ] ); |
|
123 | 123 | |
124 | 124 | // Find the end of the heredoc. |
125 | 125 | $start += 2; |
126 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
126 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
127 | 127 | |
128 | 128 | $tokens = $this->phpcsFile->getTokens(); |
129 | - $this->assertSame($tokens[($start + 4)], $tokens[$found]); |
|
129 | + $this->assertSame( $tokens[ ( $start + 4 ) ], $tokens[ $found ] ); |
|
130 | 130 | |
131 | 131 | // Find the end of the last arg. |
132 | - $start = ($found + 2); |
|
133 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
132 | + $start = ( $found + 2 ); |
|
133 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
134 | 134 | |
135 | 135 | $tokens = $this->phpcsFile->getTokens(); |
136 | - $this->assertSame($tokens[$start], $tokens[$found]); |
|
136 | + $this->assertSame( $tokens[ $start ], $tokens[ $found ] ); |
|
137 | 137 | |
138 | 138 | }//end testHeredocFunctionArg() |
139 | 139 | |
@@ -146,25 +146,25 @@ discard block |
||
146 | 146 | public function testSwitch() |
147 | 147 | { |
148 | 148 | // Find the end of the switch. |
149 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSwitch */') + 2); |
|
150 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
149 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testSwitch */' ) + 2 ); |
|
150 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
151 | 151 | |
152 | 152 | $tokens = $this->phpcsFile->getTokens(); |
153 | - $this->assertSame($tokens[($start + 28)], $tokens[$found]); |
|
153 | + $this->assertSame( $tokens[ ( $start + 28 ) ], $tokens[ $found ] ); |
|
154 | 154 | |
155 | 155 | // Find the end of the case. |
156 | 156 | $start += 9; |
157 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
157 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
158 | 158 | |
159 | 159 | $tokens = $this->phpcsFile->getTokens(); |
160 | - $this->assertSame($tokens[($start + 8)], $tokens[$found]); |
|
160 | + $this->assertSame( $tokens[ ( $start + 8 ) ], $tokens[ $found ] ); |
|
161 | 161 | |
162 | 162 | // Find the end of default case. |
163 | 163 | $start += 11; |
164 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
164 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
165 | 165 | |
166 | 166 | $tokens = $this->phpcsFile->getTokens(); |
167 | - $this->assertSame($tokens[($start + 6)], $tokens[$found]); |
|
167 | + $this->assertSame( $tokens[ ( $start + 6 ) ], $tokens[ $found ] ); |
|
168 | 168 | |
169 | 169 | }//end testSwitch() |
170 | 170 | |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | public function testStatementAsArrayValue() |
178 | 178 | { |
179 | 179 | // Test short array syntax. |
180 | - $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */') + 7); |
|
181 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
180 | + $start = ( $this->phpcsFile->findNext( T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */' ) + 7 ); |
|
181 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
182 | 182 | |
183 | 183 | $tokens = $this->phpcsFile->getTokens(); |
184 | - $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
184 | + $this->assertSame( $tokens[ ( $start + 2 ) ], $tokens[ $found ] ); |
|
185 | 185 | |
186 | 186 | // Test long array syntax. |
187 | 187 | $start += 12; |
188 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
188 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
189 | 189 | |
190 | 190 | $tokens = $this->phpcsFile->getTokens(); |
191 | - $this->assertSame($tokens[($start + 2)], $tokens[$found]); |
|
191 | + $this->assertSame( $tokens[ ( $start + 2 ) ], $tokens[ $found ] ); |
|
192 | 192 | |
193 | 193 | // Test same statement outside of array. |
194 | 194 | $start += 10; |
195 | - $found = $this->phpcsFile->findEndOfStatement($start); |
|
195 | + $found = $this->phpcsFile->findEndOfStatement( $start ); |
|
196 | 196 | |
197 | 197 | $tokens = $this->phpcsFile->getTokens(); |
198 | - $this->assertSame($tokens[($start + 3)], $tokens[$found]); |
|
198 | + $this->assertSame( $tokens[ ( $start + 3 ) ], $tokens[ $found ] ); |
|
199 | 199 | |
200 | 200 | }//end testStatementAsArrayValue() |
201 | 201 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use PHP_CodeSniffer\Files\DummyFile; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | |
17 | -class FindEndOfStatementTest extends TestCase |
|
18 | -{ |
|
17 | +class FindEndOfStatementTest extends TestCase { |
|
19 | 18 | |
20 | 19 | /** |
21 | 20 | * The PHP_CodeSniffer_File object containing parsed contents of the test case file. |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | * |
34 | 33 | * @return void |
35 | 34 | */ |
36 | - public function setUp() |
|
37 | - { |
|
35 | + public function setUp() { |
|
38 | 36 | $config = new Config(); |
39 | 37 | $config->standards = ['Generic']; |
40 | 38 | |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * |
53 | 51 | * @return void |
54 | 52 | */ |
55 | - public function tearDown() |
|
56 | - { |
|
53 | + public function tearDown() { |
|
57 | 54 | unset($this->phpcsFile); |
58 | 55 | |
59 | 56 | }//end tearDown() |
@@ -64,8 +61,7 @@ discard block |
||
64 | 61 | * |
65 | 62 | * @return void |
66 | 63 | */ |
67 | - public function testSimpleAssignment() |
|
68 | - { |
|
64 | + public function testSimpleAssignment() { |
|
69 | 65 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSimpleAssignment */') + 2); |
70 | 66 | $found = $this->phpcsFile->findEndOfStatement($start); |
71 | 67 | |
@@ -80,8 +76,7 @@ discard block |
||
80 | 76 | * |
81 | 77 | * @return void |
82 | 78 | */ |
83 | - public function testControlStructure() |
|
84 | - { |
|
79 | + public function testControlStructure() { |
|
85 | 80 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testControlStructure */') + 2); |
86 | 81 | $found = $this->phpcsFile->findEndOfStatement($start); |
87 | 82 | |
@@ -96,8 +91,7 @@ discard block |
||
96 | 91 | * |
97 | 92 | * @return void |
98 | 93 | */ |
99 | - public function testClosureAssignment() |
|
100 | - { |
|
94 | + public function testClosureAssignment() { |
|
101 | 95 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testClosureAssignment */') + 2); |
102 | 96 | $found = $this->phpcsFile->findEndOfStatement($start); |
103 | 97 | |
@@ -112,8 +106,7 @@ discard block |
||
112 | 106 | * |
113 | 107 | * @return void |
114 | 108 | */ |
115 | - public function testHeredocFunctionArg() |
|
116 | - { |
|
109 | + public function testHeredocFunctionArg() { |
|
117 | 110 | // Find the end of the function. |
118 | 111 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testHeredocFunctionArg */') + 2); |
119 | 112 | $found = $this->phpcsFile->findEndOfStatement($start); |
@@ -143,8 +136,7 @@ discard block |
||
143 | 136 | * |
144 | 137 | * @return void |
145 | 138 | */ |
146 | - public function testSwitch() |
|
147 | - { |
|
139 | + public function testSwitch() { |
|
148 | 140 | // Find the end of the switch. |
149 | 141 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testSwitch */') + 2); |
150 | 142 | $found = $this->phpcsFile->findEndOfStatement($start); |
@@ -174,8 +166,7 @@ discard block |
||
174 | 166 | * |
175 | 167 | * @return void |
176 | 168 | */ |
177 | - public function testStatementAsArrayValue() |
|
178 | - { |
|
169 | + public function testStatementAsArrayValue() { |
|
179 | 170 | // Test short array syntax. |
180 | 171 | $start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */') + 7); |
181 | 172 | $found = $this->phpcsFile->findEndOfStatement($start); |
@@ -1,29 +1,29 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /* testPassByReference */ |
4 | -function passByReference(&$var) {} |
|
4 | +function passByReference( &$var ) {} |
|
5 | 5 | |
6 | 6 | /* testArrayHint */ |
7 | -function arrayHint(array $var) {} |
|
7 | +function arrayHint( array $var ) {} |
|
8 | 8 | |
9 | 9 | /* testVariable */ |
10 | -function variable($var) {} |
|
10 | +function variable( $var ) {} |
|
11 | 11 | |
12 | 12 | /* testSingleDefaultValue */ |
13 | -function defaultValue($var1=self::CONSTANT) {} |
|
13 | +function defaultValue( $var1 = self::CONSTANT ) {} |
|
14 | 14 | |
15 | 15 | /* testDefaultValues */ |
16 | -function defaultValues($var1=1, $var2='value') {} |
|
16 | +function defaultValues( $var1 = 1, $var2 = 'value' ) {} |
|
17 | 17 | |
18 | 18 | /* testTypeHint */ |
19 | -function typeHint(foo $var1, bar $var2) {} |
|
19 | +function typeHint( foo $var1, bar $var2 ) {} |
|
20 | 20 | |
21 | 21 | class MyClass { |
22 | -/* testSelfTypeHint */ function typeSelfHint(self $var) {} |
|
22 | +/* testSelfTypeHint */ function typeSelfHint( self $var ) {} |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /* testNullableTypeHint */ |
26 | -function nullableTypeHint(?int $var1, ?\bar $var2) {} |
|
26 | +function nullableTypeHint( ?int $var1, ?\bar $var2 ) {} |
|
27 | 27 | |
28 | 28 | /* testBitwiseAndConstantExpressionDefaultValue */ |
29 | -function myFunction($a = 10 & 20) {} |
|
29 | +function myFunction( $a = 10 & 20 ) {} |
@@ -2,113 +2,113 @@ |
||
2 | 2 | |
3 | 3 | class TestMemberProperties |
4 | 4 | { |
5 | - /* testVar */ |
|
6 | - var $varA = true; |
|
7 | - |
|
8 | - /* testPublic */ |
|
9 | - public $varB = true; |
|
10 | - |
|
11 | - /* testProtected */ |
|
12 | - protected $varC = true; |
|
13 | - |
|
14 | - /* testPrivate */ |
|
15 | - private $varD = true; |
|
16 | - |
|
17 | - /* testStatic */ |
|
18 | - static $varE = true; |
|
19 | - |
|
20 | - /* testStaticVar */ |
|
21 | - static var $varF = true; |
|
22 | - |
|
23 | - /* testVarStatic */ |
|
24 | - var static $varG = true; |
|
25 | - |
|
26 | - /* testPublicStatic */ |
|
27 | - public static $varH = true; |
|
28 | - |
|
29 | - /* testProtectedStatic */ |
|
30 | - static protected $varI = true; |
|
31 | - |
|
32 | - /* testPrivateStatic */ |
|
33 | - private static $varJ = true; |
|
34 | - |
|
35 | - /* testNoPrefix */ |
|
36 | - $varK = true; |
|
37 | - |
|
38 | - /* testPublicStaticWithDocblock */ |
|
39 | - /** |
|
40 | - * Comment here. |
|
41 | - * |
|
42 | - * @phpcs:ignore Standard.Category.Sniff -- because |
|
43 | - * @var boolean |
|
44 | - */ |
|
45 | - public static $varH = true; |
|
46 | - |
|
47 | - /* testProtectedStaticWithDocblock */ |
|
48 | - /** |
|
49 | - * Comment here. |
|
50 | - * |
|
51 | - * @phpcs:ignore Standard.Category.Sniff -- because |
|
52 | - * @var boolean |
|
53 | - */ |
|
54 | - static protected $varI = true; |
|
55 | - |
|
56 | - /* testPrivateStaticWithDocblock */ |
|
57 | - /** |
|
58 | - * Comment here. |
|
59 | - * |
|
60 | - * @phpcs:ignore Standard.Category.Sniff -- because |
|
61 | - * @var boolean |
|
62 | - */ |
|
63 | - private static $varJ = true; |
|
64 | - |
|
65 | - |
|
66 | - protected static |
|
67 | - /* testGroupProtectedStatic 1 */ |
|
68 | - $varL, |
|
69 | - /* testGroupProtectedStatic 2 */ |
|
70 | - $varM, |
|
71 | - /* testGroupProtectedStatic 3 */ |
|
72 | - $varN; |
|
73 | - |
|
74 | - private |
|
75 | - /* testGroupPrivate 1 */ |
|
76 | - $varO = true, |
|
77 | - /* testGroupPrivate 2 */ |
|
78 | - $varP = array( 'a' => 'a', 'b' => 'b' ), |
|
79 | - /* testGroupPrivate 3 */ |
|
80 | - $varQ = 'string', |
|
81 | - /* testGroupPrivate 4 */ |
|
82 | - $varR = 123, |
|
83 | - /* testGroupPrivate 5 */ |
|
84 | - $varS = ONE / self::THREE, |
|
85 | - /* testGroupPrivate 6 */ |
|
86 | - $varT = [ |
|
5 | + /* testVar */ |
|
6 | + var $varA = true; |
|
7 | + |
|
8 | + /* testPublic */ |
|
9 | + public $varB = true; |
|
10 | + |
|
11 | + /* testProtected */ |
|
12 | + protected $varC = true; |
|
13 | + |
|
14 | + /* testPrivate */ |
|
15 | + private $varD = true; |
|
16 | + |
|
17 | + /* testStatic */ |
|
18 | + static $varE = true; |
|
19 | + |
|
20 | + /* testStaticVar */ |
|
21 | + static var $varF = true; |
|
22 | + |
|
23 | + /* testVarStatic */ |
|
24 | + var static $varG = true; |
|
25 | + |
|
26 | + /* testPublicStatic */ |
|
27 | + public static $varH = true; |
|
28 | + |
|
29 | + /* testProtectedStatic */ |
|
30 | + static protected $varI = true; |
|
31 | + |
|
32 | + /* testPrivateStatic */ |
|
33 | + private static $varJ = true; |
|
34 | + |
|
35 | + /* testNoPrefix */ |
|
36 | + $varK = true; |
|
37 | + |
|
38 | + /* testPublicStaticWithDocblock */ |
|
39 | + /** |
|
40 | + * Comment here. |
|
41 | + * |
|
42 | + * @phpcs:ignore Standard.Category.Sniff -- because |
|
43 | + * @var boolean |
|
44 | + */ |
|
45 | + public static $varH = true; |
|
46 | + |
|
47 | + /* testProtectedStaticWithDocblock */ |
|
48 | + /** |
|
49 | + * Comment here. |
|
50 | + * |
|
51 | + * @phpcs:ignore Standard.Category.Sniff -- because |
|
52 | + * @var boolean |
|
53 | + */ |
|
54 | + static protected $varI = true; |
|
55 | + |
|
56 | + /* testPrivateStaticWithDocblock */ |
|
57 | + /** |
|
58 | + * Comment here. |
|
59 | + * |
|
60 | + * @phpcs:ignore Standard.Category.Sniff -- because |
|
61 | + * @var boolean |
|
62 | + */ |
|
63 | + private static $varJ = true; |
|
64 | + |
|
65 | + |
|
66 | + protected static |
|
67 | + /* testGroupProtectedStatic 1 */ |
|
68 | + $varL, |
|
69 | + /* testGroupProtectedStatic 2 */ |
|
70 | + $varM, |
|
71 | + /* testGroupProtectedStatic 3 */ |
|
72 | + $varN; |
|
73 | + |
|
74 | + private |
|
75 | + /* testGroupPrivate 1 */ |
|
76 | + $varO = true, |
|
77 | + /* testGroupPrivate 2 */ |
|
78 | + $varP = array( 'a' => 'a', 'b' => 'b' ), |
|
79 | + /* testGroupPrivate 3 */ |
|
80 | + $varQ = 'string', |
|
81 | + /* testGroupPrivate 4 */ |
|
82 | + $varR = 123, |
|
83 | + /* testGroupPrivate 5 */ |
|
84 | + $varS = ONE / self::THREE, |
|
85 | + /* testGroupPrivate 6 */ |
|
86 | + $varT = [ |
|
87 | 87 | 'a' => 'a', |
88 | 88 | 'b' => 'b' |
89 | 89 | ], |
90 | - /* testGroupPrivate 7 */ |
|
91 | - $varU = __DIR__ . "/base"; |
|
90 | + /* testGroupPrivate 7 */ |
|
91 | + $varU = __DIR__ . "/base"; |
|
92 | 92 | |
93 | 93 | |
94 | - /* testMethodParam */ |
|
95 | - public function methodName($param) { |
|
96 | - /* testImportedGlobal */ |
|
97 | - global $importedGlobal = true; |
|
94 | + /* testMethodParam */ |
|
95 | + public function methodName($param) { |
|
96 | + /* testImportedGlobal */ |
|
97 | + global $importedGlobal = true; |
|
98 | 98 | |
99 | - /* testLocalVariable */ |
|
100 | - $localVariable = true; |
|
101 | - } |
|
99 | + /* testLocalVariable */ |
|
100 | + $localVariable = true; |
|
101 | + } |
|
102 | 102 | |
103 | - /* testPropertyAfterMethod */ |
|
104 | - private static $varV = true; |
|
103 | + /* testPropertyAfterMethod */ |
|
104 | + private static $varV = true; |
|
105 | 105 | |
106 | 106 | } |
107 | 107 | |
108 | 108 | interface Base |
109 | 109 | { |
110 | - /* testInterfaceProperty */ |
|
111 | - protected $anonymous; |
|
110 | + /* testInterfaceProperty */ |
|
111 | + protected $anonymous; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /* testGlobalVariable */ |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | |
94 | 94 | /* testMethodParam */ |
95 | - public function methodName($param) { |
|
95 | + public function methodName( $param ) { |
|
96 | 96 | /* testImportedGlobal */ |
97 | 97 | global $importedGlobal = true; |
98 | 98 | |
@@ -117,13 +117,12 @@ discard block |
||
117 | 117 | /* testNotAVariable */ |
118 | 118 | return; |
119 | 119 | |
120 | -$a = ( $foo == $bar ? new stdClass() : |
|
121 | - new class() { |
|
120 | +$a = ( $foo == $bar ? new stdClass() : new class() { |
|
122 | 121 | /* testNestedProperty 1 */ |
123 | 122 | public $var = true; |
124 | 123 | |
125 | 124 | /* testNestedMethodParam 1 */ |
126 | - public function something($var = false) {} |
|
125 | + public function something( $var = false ) {} |
|
127 | 126 | } |
128 | 127 | ); |
129 | 128 |
@@ -1,7 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class TestMemberProperties |
|
4 | -{ |
|
3 | +class TestMemberProperties { |
|
5 | 4 | /* testVar */ |
6 | 5 | var $varA = true; |
7 | 6 | |
@@ -105,8 +104,7 @@ discard block |
||
105 | 104 | |
106 | 105 | } |
107 | 106 | |
108 | -interface Base |
|
109 | -{ |
|
107 | +interface Base { |
|
110 | 108 | /* testInterfaceProperty */ |
111 | 109 | protected $anonymous; |
112 | 110 | } |