From 79d788b5b2c6b4ec59abb545de1643a8fcb49f2b Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Thu, 27 Aug 2020 11:56:38 +0200 Subject: [PATCH] Print 100% ending progress (#524) * Print 100% ending progress * Fix for CC bug --- src/Runners/PHPUnit/ResultPrinter.php | 13 +++++++++++-- test/Unit/Runners/PHPUnit/ResultPrinterTest.php | 9 +++++++-- test/fixtures/phpunit-fully-configured.xml | 5 ++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Runners/PHPUnit/ResultPrinter.php b/src/Runners/PHPUnit/ResultPrinter.php index 80d228cf..2c49b922 100644 --- a/src/Runners/PHPUnit/ResultPrinter.php +++ b/src/Runners/PHPUnit/ResultPrinter.php @@ -23,6 +23,7 @@ use function rtrim; use function sprintf; use function str_pad; +use function str_repeat; use function strlen; use const DIRECTORY_SEPARATOR; @@ -205,7 +206,7 @@ public function getHeader(): string { $resourceUsage = (new ResourceUsageFormatter())->resourceUsageSinceStartOfRequest(); - return "\n\n" . $resourceUsage . "\n\n"; + return "\n" . $resourceUsage . "\n\n"; } /** @@ -364,10 +365,18 @@ private function printFeedbackItem(string $item): void $this->printFeedbackItemColor($item); ++$this->column; ++$this->casesProcessed; - if ($this->column !== $this->maxColumn) { + if ($this->column !== $this->maxColumn && $this->casesProcessed < $this->totalCases) { return; } + if ( + $this->casesProcessed > 0 + && $this->casesProcessed === $this->totalCases + && ($pad = $this->maxColumn - $this->column) > 0 + ) { + $this->output->write(str_repeat(' ', $pad)); + } + $this->output->write($this->getProgress()); $this->println(); } diff --git a/test/Unit/Runners/PHPUnit/ResultPrinterTest.php b/test/Unit/Runners/PHPUnit/ResultPrinterTest.php index 1cd9e5ed..ec36bcba 100644 --- a/test/Unit/Runners/PHPUnit/ResultPrinterTest.php +++ b/test/Unit/Runners/PHPUnit/ResultPrinterTest.php @@ -16,6 +16,7 @@ use function defined; use function file_put_contents; use function sprintf; +use function str_repeat; use function uniqid; /** @@ -159,7 +160,7 @@ public function testGetHeader(): void $header = $this->printer->getHeader(); static::assertMatchesRegularExpression( - "/\n\nTime: ([.:]?[0-9]{1,3})+ ?" . + "/\nTime: ([.:]?[0-9]{1,3})+ ?" . '(minute|minutes|second|seconds|ms|)?,' . " Memory:[\\s][0-9]+([.][0-9]{1,2})? ?M[Bb]\n\n/", $header @@ -287,7 +288,7 @@ public function testPrintFeedbackForMixed(): void $this->printer->addTest($this->mixedSuite); $this->printer->printFeedback($this->mixedSuite); $contents = $this->output->fetch(); - static::assertSame('.F..E.F.WSSR.F.WSSR', $contents); + static::assertSame(".F..E.F.WSSR.F.WSSR 19 / 19 (100%)\n", $contents); } public function testPrintFeedbackForMoreThan100Suites(): void @@ -324,6 +325,8 @@ public function testPrintFeedbackForMoreThan100Suites(): void $expected .= '.'; } + $expected .= sprintf("%s 120 / 120 (100%%)\n", str_repeat(' ', $firstRowColumns - $secondRowColumns)); + static::assertSame($expected, $feedback); } @@ -361,6 +364,8 @@ public function testResultPrinterAdjustsTotalCountForDataProviders(): void $expected .= '.'; } + $expected .= sprintf("%s 66 / 66 (100%%)\n", str_repeat(' ', $firstRowColumns - $secondRowColumns)); + static::assertSame($expected, $feedback); } diff --git a/test/fixtures/phpunit-fully-configured.xml b/test/fixtures/phpunit-fully-configured.xml index 2e279150..1cdc9c5e 100644 --- a/test/fixtures/phpunit-fully-configured.xml +++ b/test/fixtures/phpunit-fully-configured.xml @@ -9,8 +9,11 @@ ./passing_tests/GroupsTest.php +