diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48b8bf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/ diff --git a/src/CodewarsResultPrinter.php b/src/CodewarsResultPrinter.php index 02dd1f1..b748bf0 100644 --- a/src/CodewarsResultPrinter.php +++ b/src/CodewarsResultPrinter.php @@ -24,20 +24,16 @@ class CodewarsResultPrinter extends DefaultResultPrinter * @var TestSuite */ private $wrapperSuite = null; - /** - * @var bool - */ - protected $lastTestFailed = false; - + // Temporarily store failure messages so that the outputs can be written before them. + private $failures = array(); /** * An error occurred. */ public function addError(Test $test, \Throwable $t, float $time): void { - $this->lastTestFailed = true; - $this->write(sprintf("\n%s\n", self::getMessage($t))); - $this->write(sprintf("\n%s\n", self::escapeLF(self::getDetails($t)))); + $this->failures[] = sprintf("\n%s\n", self::getMessage($t)); + $this->failures[] = sprintf("\n%s\n", self::escapeLF(self::getDetails($t))); } /** @@ -45,9 +41,8 @@ public function addError(Test $test, \Throwable $t, float $time): void */ public function addWarning(Test $test, Warning $e, float $time): void { - $this->lastTestFailed = true; - $this->write(sprintf("\n%s\n", self::getMessage($e))); - $this->write(sprintf("\n%s\n", self::escapeLF(self::getDetails($e)))); + $this->failures[] = sprintf("\n%s\n", self::getMessage($e)); + $this->failures[] = sprintf("\n%s\n", self::escapeLF(self::getDetails($e))); } /** @@ -55,13 +50,11 @@ public function addWarning(Test $test, Warning $e, float $time): void */ public function addFailure(Test $test, AssertionFailedError $e, float $time): void { - $this->lastTestFailed = true; $msg = self::getMessage($e); if ($e instanceof ExpectationFailedException) { $msg .= self::getAssertionDetails($e); } - $this->write(sprintf("\n%s\n", self::escapeLF($msg))); - $this->write(sprintf("\n%s\n", self::escapeLF(self::getDetails($e)))); + $this->failures[] = sprintf("\n%s\n", self::escapeLF($msg)); } /** @@ -130,6 +123,7 @@ public function endTestSuite(TestSuite $suite): void public function startTest(Test $test): void { $this->write(sprintf("\n%s\n", $test->getName())); + $this->failures = array(); } /** @@ -137,9 +131,16 @@ public function startTest(Test $test): void */ public function endTest(Test $test, float $time): void { - if (!$this->lastTestFailed) { + if (\method_exists($test, 'hasOutput') && \method_exists($test, 'getActualOutput')) { + if ($test->hasOutput()) { + $this->write($test->getActualOutput()); + } + } + + if (empty($this->failures)) { $this->write("\nTest Passed\n"); - $this->lastTestFailed = false; + } else { + $this->write(join("\n", $this->failures)); } $this->write(sprintf("\n%.4f\n", $time * 1000)); }