From 0640a622eb2107d4332913ef384808570b115a7f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 14 Jun 2019 14:23:37 -0400 Subject: [PATCH] Civi/Test/TAP - Replace Symfony YAML dependency This allows two paths: 1. If you have the YAML PECL extension, then that will be used. To get the best output, you can install it. 2. If you don't, then it'll output JSON. JSON is considered valid YAML. It's not clear that everyone reading the document will handle the full range YAML (incl JSON), but... we don't actually have any listeners that care to parse the TAP output... --- Civi/Test/TAP.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Civi/Test/TAP.php b/Civi/Test/TAP.php index 21bdb1e0bd..5b432ac953 100644 --- a/Civi/Test/TAP.php +++ b/Civi/Test/TAP.php @@ -97,10 +97,21 @@ class TAP extends \PHPUnit\Util\Printer implements \PHPUnit\Framework\TestListen ); } } - $yaml = new \Symfony\Component\Yaml\Dumper(); - $this - ->write(sprintf(" ---\n%s ...\n", $yaml - ->dump($diagnostic, 2, 2))); + + 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); + } + + $this->write($content); } /** -- 2.25.1