Skip to content

Commit 4cb0190

Browse files
committed
Runner: fix progress bar when running in parallel
Rodrigo and me came across this while debugging something completely different. Turns out the split between fixable/fixed error vs warnings, which was necessary in 4.0 to allow for the exit code change, was breaking the progress bar display when parallel processing was enabled. Basically, parallel processing "mocks" the accumulated fixable/fixed error and warning counts via a `DummyFile` before calling `Runner::printProgress()`. Then the `Runner::printProgress()` method calls the `File::getFixed()` method, however, that method doesn't look at the "split" fixed counts, but at the accumulated total fixes, but as this is a mocked `DummyFile`, that number will always be `0`. IIRC, updating the `File::getFixed()` method to calculate the number based on the split fixed errors and warnings was breaking other things, which is why it was left as-is. The down-side of that, as we now discovered, is that the progress bar when running in parallel would always just show a `.` and not the `F` when files were fixed. Either way, this should be fixed now. Includes a test via the new bashunit end-to-end testsuite.
1 parent bd2d185 commit 4cb0190

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ public function printProgress(File $file, $numFiles, $numProcessed)
791791
$errors = $file->getErrorCount();
792792
$warnings = $file->getWarningCount();
793793
$fixable = $file->getFixableCount();
794-
$fixed = $file->getFixedCount();
794+
$fixed = ($file->getFixedErrorCount() + $file->getFixedWarningCount());
795795

796796
if (PHP_CODESNIFFER_CBF === true) {
797797
// Files with fixed errors or warnings are F (green).

tests/EndToEnd/phpcbf_test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ function test_phpcbf_returns_error_on_issues() {
2626
assert_contains "A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE" "$OUTPUT"
2727
}
2828

29+
function test_phpcbf_progressbar_shows_fixes_with_parallel_on() {
30+
OUTPUT="$( { bin/phpcbf --no-colors --parallel=10 --no-cache --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
31+
assert_successful_code
32+
33+
assert_contains "F 1 / 1 (100%)" "$OUTPUT"
34+
}
35+
2936
function test_phpcbf_bug_1112() {
3037
# See https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/1112
3138
if [[ "$(uname)" == "Darwin" ]]; then

0 commit comments

Comments
 (0)