Skip to content

Commit d134cc1

Browse files
committed
Separated error and assertion failure state fields.
1 parent ef9b1d4 commit d134cc1

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/Printer.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ trait Printer
1010
/**
1111
* The exception thrown by the last test.
1212
*
13-
* @var \Exception|null
13+
* @var ExceptionWrapper|null
1414
*/
1515
protected $exception;
1616

17+
/**
18+
* The assertion failure thrown by the last test.
19+
*
20+
* @var AssertionFailedError|null
21+
*/
22+
protected $failure;
23+
1724
/**
1825
* PHPUnit built-in progress indication character, e.g. E for error.
1926
*
@@ -46,7 +53,7 @@ trait Printer
4653
*/
4754
protected function onStartTest()
4855
{
49-
$this->exception = $this->progress = null;
56+
$this->exception = $this->failure = $this->progress = null;
5057
$this->lastColour = 'fg-green,bold';
5158
}
5259

@@ -93,9 +100,8 @@ protected function onEndTest($test, $time)
93100
$this->writeWithColor($this->lastColour, $this->describeTest($test), false);
94101
$this->writePerformance($time);
95102

96-
if ($this->exception) {
97-
$this->writeException($this->exception);
98-
}
103+
$this->exception && $this->writeException($this->exception);
104+
$this->failure && $this->writeAssertionFailure($this->failure);
99105
}
100106

101107
protected function describeTest($test)
@@ -126,34 +132,25 @@ protected function writePerformance($time)
126132
}
127133

128134
/**
129-
* Writes the specified exception to the output buffer.
135+
* Writes the specified assertion failure's message to the output buffer.
130136
*
131-
* @param \Exception $exception Exception.
137+
* @param AssertionFailedError $assertionFailure Assertion failure.
132138
*/
133-
protected function writeException(\Exception $exception)
134-
{
135-
if ($exception instanceof \PHPUnit_Framework_AssertionFailedError
136-
|| $exception instanceof AssertionFailedError) {
137-
$this->writeAssertionFailure($exception);
138-
} elseif ($exception instanceof \PHPUnit_Framework_ExceptionWrapper
139-
|| $exception instanceof ExceptionWrapper) {
140-
$this->writeExceptionTrace($exception);
141-
}
142-
}
143-
144-
protected function writeAssertionFailure($exception)
139+
protected function writeAssertionFailure($assertionFailure)
145140
{
146141
$this->writeNewLine();
147142

148-
foreach (explode("\n", $exception) as $line) {
143+
foreach (explode("\n", $assertionFailure) as $line) {
149144
$this->writeWithColor('fg-red', $line);
150145
}
151146
}
152147

153148
/**
154-
* @param ExceptionWrapper $exception
149+
* Writes the specified exception's message to the output buffer.
150+
*
151+
* @param ExceptionWrapper $exception Exception.
155152
*/
156-
protected function writeExceptionTrace($exception)
153+
protected function writeException($exception)
157154
{
158155
$this->writeNewLine();
159156

@@ -207,7 +204,7 @@ protected function onAddFailure($e)
207204
{
208205
$this->writeProgressWithColor('fg-red,bold', 'F');
209206

210-
$this->exception = $e;
207+
$this->failure = $e;
211208
$this->lastTestFailed = true;
212209
$this->flawless = false;
213210
}

0 commit comments

Comments
 (0)