Skip to content

Commit

Permalink
Changed success progress indicator ('.') to be red after an error or …
Browse files Browse the repository at this point in the history
…failure occurs.
  • Loading branch information
Bilge committed Jul 25, 2017
1 parent 5bd117e commit 0543bf4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ trait Printer
*/
protected $lastColour;

/**
* Indicates whether any errors or exceptions have occurred during the entire test run.
*
* @var bool
*/
protected $flawless = true;

private static $performanceThresholds = [
'fg-red' => 1000,
'fg-yellow' => 200,
Expand All @@ -50,7 +57,7 @@ protected function onStartTest()
protected function writeProgress($progress)
{
// Record progress so it can be written later instead of at start of line.
$this->progress = $progress;
$this->progress = $this->flawless ? $progress : $this->formatWithColor('fg-red', $progress);

++$this->numTestsRun;
}
Expand Down Expand Up @@ -157,6 +164,7 @@ protected function onAddError(\Exception $e)

$this->exception = $e;
$this->lastTestFailed = true;
$this->flawless = false;
}

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

$this->exception = $e;
$this->lastTestFailed = true;
$this->flawless = false;
}
}
15 changes: 15 additions & 0 deletions test/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ public function provideData()
'baz' => ['qux'],
];
}

/**
* @dataProvider provideSuccessesAndFailures
*/
public function testSuccessAfterFailure($bool)
{
self::assertTrue($bool);
}

public function provideSuccessesAndFailures()
{
for ($i = 0; $i < 4; ++$i) {
yield [$i !== 1];
}
}
}
8 changes: 4 additions & 4 deletions test/functional/diff failure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ PHPUnit %s
--- Expected
+++ Actual
@@ @@
[31m-foo[0m
[31m+LogicException: foo[0m
[31m-%Sfoo%S[0m
[31m+%SLogicException: foo%S[0m

%s%eCapabilitiesTest.php:%i

Expand All @@ -32,8 +32,8 @@ Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-foo
+LogicException: foo
-%Sfoo%S
+%SLogicException: foo%S

%s%eCapabilitiesTest.php:%i

Expand Down
2 changes: 1 addition & 1 deletion test/functional/risky.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ PHPUnit %s


Time: %s

%A
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
34 changes: 34 additions & 0 deletions test/functional/success after failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Successful tests following a failure have coloured progress marker.

--ARGS--
-c test --colors=always test/CapabilitiesTest --filter '::testSuccessAfterFailure\h'

--FILE_EXTERNAL--
PHPUnit runner.php

--EXPECTF--
PHPUnit %s

25% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #0 (true) (%i ms)
50% F ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #1 (false) (%i ms)

Failed asserting that false is true.

%s%eCapabilitiesTest.php:%i

75% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #2 (true) (%i ms)
100% . ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #3 (true) (%i ms)


Time: %s

There was 1 failure:

1) ScriptFUSIONTest\PHPUnitImmediateExceptionPrinter\CapabilitiesTest::testSuccessAfterFailure with data set #1 (false)
Failed asserting that false is true.

%s%eCapabilitiesTest.php:%i

FAILURES!
Tests: 4, Assertions: 4, Failures: 1.

0 comments on commit 0543bf4

Please sign in to comment.