Merge pull request #15315 from MegaphoneJon/reporting-20
[civicrm-core.git] / Civi / Test / TAP.php
index 21bdb1e0bdb66607db2a724b0d5e95835b333524..5b432ac9530d5a66f6639494dc52684e781cae10 100644 (file)
@@ -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);
   }
 
   /**