diff --git a/src/Report/Text.php b/src/Report/Text.php index ab8daae7..a307aa4b 100644 --- a/src/Report/Text.php +++ b/src/Report/Text.php @@ -306,8 +306,10 @@ private function printCoverageCounts(int $numberOfCoveredElements, int $totalNum private function format(string $color, int $padding, false|string $string): string { - $reset = $color ? self::COLOR_RESET : ''; + if ($color === '') { + return (string) $string . PHP_EOL; + } - return $color . str_pad((string) $string, $padding) . $reset . PHP_EOL; + return $color . str_pad((string) $string, $padding) . self::COLOR_RESET . PHP_EOL; } } diff --git a/tests/_files/BankAccount-text-line.txt b/tests/_files/BankAccount-text-line.txt index 4f188c76..cbc92cda 100644 --- a/tests/_files/BankAccount-text-line.txt +++ b/tests/_files/BankAccount-text-line.txt @@ -1,9 +1,9 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: + + Summary: Classes: 0.00% (0/1) Methods: 75.00% (3/4) Lines: 62.50% (5/8) diff --git a/tests/_files/BankAccount-text-path.txt b/tests/_files/BankAccount-text-path.txt index 488e34ff..b18ac71c 100644 --- a/tests/_files/BankAccount-text-path.txt +++ b/tests/_files/BankAccount-text-path.txt @@ -1,9 +1,9 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: + + Summary: Classes: 0.00% (0/1) Methods: 75.00% (3/4) Paths: 60.00% (3/5) diff --git a/tests/_files/BankAccount-text-summary.txt b/tests/_files/BankAccount-text-summary.txt index 952abd17..cf8e5238 100644 --- a/tests/_files/BankAccount-text-summary.txt +++ b/tests/_files/BankAccount-text-summary.txt @@ -1,7 +1,7 @@ Code Coverage Report Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 62.50% (5/8) + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 62.50% (5/8) diff --git a/tests/_files/BankAccountWithUncovered-text-line.txt b/tests/_files/BankAccountWithUncovered-text-line.txt index 85693d8a..ee7757ba 100644 --- a/tests/_files/BankAccountWithUncovered-text-line.txt +++ b/tests/_files/BankAccountWithUncovered-text-line.txt @@ -1,11 +1,11 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: - Classes: 0.00% (0/2) - Methods: 37.50% (3/8) + + Summary: + Classes: 0.00% (0/2) + Methods: 37.50% (3/8) Lines: 31.25% (5/16) BankAccount diff --git a/tests/_files/BankAccountWithoutUncovered-text-line.txt b/tests/_files/BankAccountWithoutUncovered-text-line.txt index 4f188c76..cbc92cda 100644 --- a/tests/_files/BankAccountWithoutUncovered-text-line.txt +++ b/tests/_files/BankAccountWithoutUncovered-text-line.txt @@ -1,9 +1,9 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: + + Summary: Classes: 0.00% (0/1) Methods: 75.00% (3/4) Lines: 62.50% (5/8) diff --git a/tests/_files/NamespacedBankAccount-text-with-colors.txt b/tests/_files/NamespacedBankAccount-text-with-colors.txt new file mode 100644 index 00000000..83f3901e --- /dev/null +++ b/tests/_files/NamespacedBankAccount-text-with-colors.txt @@ -0,0 +1,14 @@ + + +Code Coverage Report:  + %s  +  + Summary:  + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 62.50% (5/8) + +SomeNamespace\BankAccount + Methods: ( 0/ 0) Lines: ( 0/ 0) +SomeNamespace\BankAccountTrait + Methods: 75.00% ( 3/ 4) Lines: 62.50% ( 5/ 8) diff --git a/tests/_files/NamespacedBankAccount-text.txt b/tests/_files/NamespacedBankAccount-text.txt index 7cede93c..f535d120 100644 --- a/tests/_files/NamespacedBankAccount-text.txt +++ b/tests/_files/NamespacedBankAccount-text.txt @@ -1,9 +1,9 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: + + Summary: Classes: 0.00% (0/1) Methods: 75.00% (3/4) Lines: 62.50% (5/8) diff --git a/tests/_files/class-with-anonymous-function-text.txt b/tests/_files/class-with-anonymous-function-text.txt index 6d7e2a07..905bdd1a 100644 --- a/tests/_files/class-with-anonymous-function-text.txt +++ b/tests/_files/class-with-anonymous-function-text.txt @@ -1,9 +1,9 @@ -Code Coverage Report: +Code Coverage Report: %s - - Summary: + + Summary: Classes: 100.00% (1/1) Methods: 100.00% (1/1) Lines: 100.00% (8/8) diff --git a/tests/_files/ignored-lines-text.txt b/tests/_files/ignored-lines-text.txt index 55f57afb..8592fb47 100644 --- a/tests/_files/ignored-lines-text.txt +++ b/tests/_files/ignored-lines-text.txt @@ -1,10 +1,10 @@ -Code Coverage Report:%w +Code Coverage Report: %s -%w - Summary:%w - Classes: (0/0) - Methods: (0/0) + + Summary: + Classes: (0/0) + Methods: (0/0) Lines: 100.00% (1/1) diff --git a/tests/tests/Report/TextTest.php b/tests/tests/Report/TextTest.php index 16a99d36..8cefd57c 100644 --- a/tests/tests/Report/TextTest.php +++ b/tests/tests/Report/TextTest.php @@ -57,6 +57,16 @@ public function testTextForNamespacedBankAccountTest(): void ); } + public function testTextForNamespacedBankAccountTestWhenColorsAreEnabled(): void + { + $text = new Text(Thresholds::default(), true, false); + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'NamespacedBankAccount-text-with-colors.txt', + str_replace(PHP_EOL, "\n", $text->process($this->getLineCoverageForNamespacedBankAccount(), true)), + ); + } + public function testTextForFileWithIgnoredLines(): void { $text = new Text(Thresholds::default(), false, false);