- /**
- * A failure occurred.
- *
- * @param \PHPUnit\Framework\Test $test
- * @param \PHPUnit\Framework\AssertionFailedError $e
- * @param float $time
- */
- public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time) {
- $this
- ->writeNotOk($test, 'Failure');
- $message = explode("\n", \PHPUnit\Framework\TestFailure::exceptionToString($e));
- $diagnostic = array(
- 'message' => $message[0],
- 'severity' => 'fail',
- );
- if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
- $cf = $e
- ->getComparisonFailure();
- if ($cf !== NULL) {
- $diagnostic['data'] = array(
- 'got' => $cf
- ->getActual(),
- 'expected' => $cf
- ->getExpected(),
- );
+ if (function_exists('yaml_emit')) {
+ $content = \yaml_emit($diagnostic, YAML_UTF8_ENCODING);
+ $content = ' ' . strtr($content, ["\n" => "\n "]);
+ }
+ else {
+ // Any valid JSON document is a valid YAML document.
+ $content = json_encode($diagnostic, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+ // For closest match, drop outermost {}'s. Realign indentation.
+ $content = substr($content, 0, strrpos($content, "}")) . ' }';
+ $content = ' ' . ltrim($content);
+ $content = sprintf(" ---\n%s\n ...\n", $content);