Skip to content

Commit 4a08484

Browse files
committed
Test bootstrap/printPHPCodeSnifferTestOutput(): bug fix
PR 2289 added a count of the number of test case files to the test output, however did not take into account that when only the unit tests for the utility functions would be run, i.e. `phpunit --filter FindExtendedClassNameTest`, the `$GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']` variable would not have any arrays in it. This adds some minor defensive coding which gets rid of the error messages which would be generated in that situation.
1 parent 390bffe commit 4a08484

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tests/bootstrap.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,33 @@ class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult');
5252
*/
5353
function printPHPCodeSnifferTestOutput()
5454
{
55+
echo PHP_EOL.PHP_EOL;
56+
57+
$output = 'The test files';
58+
$data = [];
59+
5560
$codeCount = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']);
56-
$files = call_user_func_array('array_merge', $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']);
57-
$files = array_unique($files);
58-
$fileCount = count($files);
61+
if (empty($GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']) === false) {
62+
$files = call_user_func_array('array_merge', $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES']);
63+
$files = array_unique($files);
64+
$fileCount = count($files);
65+
66+
$output = '%d sniff test files';
67+
$data[] = $fileCount;
68+
}
69+
70+
$output .= ' generated %d unique error codes';
71+
$data[] = $codeCount;
5972

60-
echo PHP_EOL.PHP_EOL;
61-
echo "$fileCount sniff test files generated $codeCount unique error codes";
6273
if ($codeCount > 0) {
6374
$fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']);
6475
$percent = round(($fixes / $codeCount * 100), 2);
65-
echo "; $fixes were fixable ($percent%)";
76+
77+
$output .= '; %d were fixable (%d%%)';
78+
$data[] = $fixes;
79+
$data[] = $percent;
6680
}
6781

82+
vprintf($output, $data);
83+
6884
}//end printPHPCodeSnifferTestOutput()

0 commit comments

Comments
 (0)