Skip to content

Commit 0543bf4

Browse files
committed
Changed success progress indicator ('.') to be red after an error or failure occurs.
1 parent 5bd117e commit 0543bf4

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

src/Printer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ trait Printer
2727
*/
2828
protected $lastColour;
2929

30+
/**
31+
* Indicates whether any errors or exceptions have occurred during the entire test run.
32+
*
33+
* @var bool
34+
*/
35+
protected $flawless = true;
36+
3037
private static $performanceThresholds = [
3138
'fg-red' => 1000,
3239
'fg-yellow' => 200,
@@ -50,7 +57,7 @@ protected function onStartTest()
5057
protected function writeProgress($progress)
5158
{
5259
// Record progress so it can be written later instead of at start of line.
53-
$this->progress = $progress;
60+
$this->progress = $this->flawless ? $progress : $this->formatWithColor('fg-red', $progress);
5461

5562
++$this->numTestsRun;
5663
}
@@ -157,6 +164,7 @@ protected function onAddError(\Exception $e)
157164

158165
$this->exception = $e;
159166
$this->lastTestFailed = true;
167+
$this->flawless = false;
160168
}
161169

162170
/**
@@ -170,5 +178,6 @@ protected function onAddFailure($e)
170178

171179
$this->exception = $e;
172180
$this->lastTestFailed = true;
181+
$this->flawless = false;
173182
}
174183
}

test/CapabilitiesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ public function provideData()
5959
'baz' => ['qux'],
6060
];
6161
}
62+
63+
/**
64+
* @dataProvider provideSuccessesAndFailures
65+
*/
66+
public function testSuccessAfterFailure($bool)
67+
{
68+
self::assertTrue($bool);
69+
}
70+
71+
public function provideSuccessesAndFailures()
72+
{
73+
for ($i = 0; $i < 4; ++$i) {
74+
yield [$i !== 1];
75+
}
76+
}
6277
}

test/functional/diff failure.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ PHPUnit %s
1616
--- Expected
1717
+++ Actual
1818
@@ @@
19-
[31m-foo[0m
20-
[31m+LogicException: foo[0m
19+
[31m-%Sfoo%S[0m
20+
[31m+%SLogicException: foo%S[0m
2121

2222
%s%eCapabilitiesTest.php:%i
2323

@@ -32,8 +32,8 @@ Failed asserting that two strings are identical.
3232
--- Expected
3333
+++ Actual
3434
@@ @@
35-
-foo
36-
+LogicException: foo
35+
-%Sfoo%S
36+
+%SLogicException: foo%S
3737

3838
%s%eCapabilitiesTest.php:%i
3939

test/functional/risky.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ PHPUnit %s
1414

1515

1616
Time: %s
17-
17+
%A
1818
OK, but incomplete, skipped, or risky tests!
1919
Tests: 1, Assertions: 0, Risky: 1.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Successful tests following a failure have coloured progress marker.
3+
4+
--ARGS--
5+
-c test --colors=always test/CapabilitiesTest --filter '::testSuccessAfterFailure\h'
6+
7+
--FILE_EXTERNAL--
8+
PHPUnit runner.php
9+
10+
--EXPECTF--
11+
PHPUnit %s
12+
13+
25% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #0 (true) (%i ms)
14+
50% F ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #1 (false) (%i ms)
15+
16+
Failed asserting that false is true.
17+

18+
%s%eCapabilitiesTest.php:%i
19+

20+
75% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #2 (true) (%i ms)
21+
100% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #3 (true) (%i ms)
22+
23+
24+
Time: %s
25+
26+
There was 1 failure:
27+
28+
1) ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #1 (false)
29+
Failed asserting that false is true.
30+
31+
%s%eCapabilitiesTest.php:%i
32+
33+
FAILURES!
34+
Tests: 4, Assertions: 4, Failures: 1.

0 commit comments

Comments
 (0)