Civi/Test/TAP - Replace Symfony YAML dependency
authorTim Otten <totten@civicrm.org>
Fri, 14 Jun 2019 18:23:37 +0000 (14:23 -0400)
committerTim Otten <totten@civicrm.org>
Fri, 14 Jun 2019 20:01:58 +0000 (16:01 -0400)
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

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);
   }
 
   /**