Created
June 29, 2020 05:44
-
-
Save Petah/6d466d8e491f90ae99ffe0fc7195e687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPUnit\Framework\TestListener; | |
class OutputListener implements TestListener | |
{ | |
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) | |
{ | |
echo PHP_EOL; | |
echo PHP_EOL . 'ERROR: ' . get_class($test) . ' ' . $test->getName(); | |
echo PHP_EOL; | |
echo PHP_EOL . $e->getMessage(); | |
echo PHP_EOL; | |
echo PHP_EOL . $this->exceptionTraceToString($e); | |
echo PHP_EOL; | |
} | |
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) | |
{ | |
echo PHP_EOL; | |
echo PHP_EOL . 'FAILURE: ' . get_class($test) . ' ' . $test->getName(); | |
echo PHP_EOL; | |
echo PHP_EOL . $e->getMessage(); | |
echo PHP_EOL; | |
} | |
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) | |
{ | |
} | |
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) | |
{ | |
} | |
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) | |
{ | |
} | |
public function startTest(PHPUnit_Framework_Test $test) | |
{ | |
echo PHP_EOL . get_class($test) . ' ' . $test->getName(); | |
} | |
public function endTest(PHPUnit_Framework_Test $test, $time) | |
{ | |
} | |
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) | |
{ | |
} | |
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) | |
{ | |
} | |
private function exceptionTraceToString($exception) | |
{ | |
$trace = []; | |
foreach ($exception->getSerializableTrace() as $line) { | |
$text = ''; | |
if (isset($line['line'])) { | |
$text .= '#' . $line['line']; | |
} | |
$text .= ' '; | |
if (isset($line['class'])) { | |
$text .= $line['class']; | |
} | |
if (isset($line['type'])) { | |
$text .= $line['type']; | |
} | |
if (isset($line['function'])) { | |
$text .= $line['function']; | |
} | |
$text .= ' '; | |
if (isset($line['file'])) { | |
$text .= $line['file']; | |
} | |
$trace[] = trim($text); | |
} | |
$trace = implode(PHP_EOL, $trace); | |
return $trace; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit> | |
... | |
<listeners> | |
<listener class="OutputListener" /> | |
</listeners> | |
... | |
</phpunit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment