4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
15 class TAPLegacy
extends \PHPUnit\Util\Printer
implements \PHPUnit\Framework\TestListener
{
20 protected $testNumber = 0;
25 protected $testSuiteLevel = 0;
30 protected $testSuccessful = TRUE;
37 * @throws \PHPUnit\Framework\Exception
39 * @since Method available since Release 3.3.4
41 public function __construct($out = NULL) {
42 parent
::__construct($out);
44 ->write("TAP version 13\n");
50 * @param \PHPUnit\Framework\Test $test
51 * @param \Exception $e
54 public function addError(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
56 ->writeNotOk($test, 'Error');
62 * @param \PHPUnit\Framework\Test $test
63 * @param \PHPUnit\Framework\AssertionFailedError $e
66 public function addFailure(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\AssertionFailedError
$e, $time) {
68 ->writeNotOk($test, 'Failure');
69 $message = explode("\n", \PHPUnit\Framework\TestFailure
::exceptionToString($e));
71 'message' => $message[0],
74 if ($e instanceof \PHPUnit\Framework\ExpectationFailedException
) {
76 ->getComparisonFailure();
78 $diagnostic['data'] = array(
87 if (function_exists('yaml_emit')) {
88 $content = \
yaml_emit($diagnostic, YAML_UTF8_ENCODING
);
89 $content = ' ' . strtr($content, ["\n" => "\n "]);
92 // Any valid JSON document is a valid YAML document.
93 $content = json_encode($diagnostic, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
94 // For closest match, drop outermost {}'s. Realign indentation.
95 $content = substr($content, 0, strrpos($content, "}")) . ' }';
96 $content = ' ' . ltrim($content);
97 $content = sprintf(" ---\n%s\n ...\n", $content);
100 $this->write($content);
106 * @param \PHPUnit\Framework\Test $test
107 * @param \Exception $e
110 public function addIncompleteTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
112 ->writeNotOk($test, '', 'TODO Incomplete Test');
118 * @param \PHPUnit\Framework\Test $test
119 * @param \Exception $e
122 * @since Method available since Release 4.0.0
124 public function addRiskyTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
126 ->write(sprintf("ok %d - # RISKY%s\n", $this->testNumber
, $e
127 ->getMessage() != '' ?
' ' . $e
128 ->getMessage() : ''));
129 $this->testSuccessful
= FALSE;
135 * @param \PHPUnit\Framework\Test $test
136 * @param \Exception $e
139 * @since Method available since Release 3.0.0
141 public function addSkippedTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
143 ->write(sprintf("ok %d - # SKIP%s\n", $this->testNumber
, $e
144 ->getMessage() != '' ?
' ' . $e
145 ->getMessage() : ''));
146 $this->testSuccessful
= FALSE;
152 * @param \PHPUnit\Framework\Test $test
153 * @param \PHPUnit\Framework\Warning $e
156 * @since Method available since Release 3.0.0
158 public function addWarning(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\Warning
$e, $time) {
160 ->write(sprintf("ok %d - # Warning%s\n", $this->testNumber
, $e
161 ->getMessage() != '' ?
' ' . $e
162 ->getMessage() : ''));
163 $this->testSuccessful
= FALSE;
167 * A testsuite started.
169 * @param \PHPUnit\Framework\TestSuite $suite
171 public function startTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
172 $this->testSuiteLevel++
;
178 * @param \PHPUnit\Framework\TestSuite $suite
180 public function endTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
181 $this->testSuiteLevel
--;
182 if ($this->testSuiteLevel
== 0) {
184 ->write(sprintf("1..%d\n", $this->testNumber
));
191 * @param \PHPUnit\Framework\Test $test
193 public function startTest(\PHPUnit\Framework\Test
$test) {
195 $this->testSuccessful
= TRUE;
201 * @param \PHPUnit\Framework\Test $test
204 public function endTest(\PHPUnit\Framework\Test
$test, $time) {
205 if ($this->testSuccessful
=== TRUE) {
207 ->write(sprintf("ok %d - %s\n", $this->testNumber
, \PHPUnit\Util\Test
::describe($test)));
210 ->writeDiagnostics($test);
214 * @param \PHPUnit\Framework\Test $test
215 * @param string $prefix
216 * @param string $directive
218 protected function writeNotOk(\PHPUnit\Framework\Test
$test, $prefix = '', $directive = '') {
220 ->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber
, $prefix != '' ?
$prefix . ': ' : '', \PHPUnit\Util\Test
::describe($test), $directive != '' ?
' # ' . $directive : ''));
221 $this->testSuccessful
= FALSE;
225 * @param \PHPUnit\Framework\Test $test
227 private function writeDiagnostics(\PHPUnit\Framework\Test
$test) {
228 if (!$test instanceof \PHPUnit\Framework\TestCase
) {
235 foreach (explode("\n", trim($test
236 ->getActualOutput())) as $line) {
238 ->write(sprintf("# %s\n", $line));