4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
29 class TAP
extends \PHPUnit\Util\Printer
implements \PHPUnit\Framework\TestListener
{
34 protected $testNumber = 0;
39 protected $testSuiteLevel = 0;
44 protected $testSuccessful = TRUE;
51 * @throws \PHPUnit\Framework\Exception
53 * @since Method available since Release 3.3.4
55 public function __construct($out = NULL) {
56 parent
::__construct($out);
58 ->write("TAP version 13\n");
64 * @param \PHPUnit\Framework\Test $test
65 * @param \Exception $e
68 public function addError(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
70 ->writeNotOk($test, 'Error');
76 * @param \PHPUnit\Framework\Test $test
77 * @param \PHPUnit\Framework\AssertionFailedError $e
80 public function addFailure(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\AssertionFailedError
$e, $time) {
82 ->writeNotOk($test, 'Failure');
83 $message = explode("\n", \PHPUnit\Framework\TestFailure
::exceptionToString($e));
85 'message' => $message[0],
88 if ($e instanceof \PHPUnit\Framework\ExpectationFailedException
) {
90 ->getComparisonFailure();
92 $diagnostic['data'] = array(
101 if (function_exists('yaml_emit')) {
102 $content = \
yaml_emit($diagnostic, YAML_UTF8_ENCODING
);
103 $content = ' ' . strtr($content, ["\n" => "\n "]);
106 // Any valid JSON document is a valid YAML document.
107 $content = json_encode($diagnostic, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
108 // For closest match, drop outermost {}'s. Realign indentation.
109 $content = substr($content, 0, strrpos($content, "}")) . ' }';
110 $content = ' ' . ltrim($content);
111 $content = sprintf(" ---\n%s\n ...\n", $content);
114 $this->write($content);
120 * @param \PHPUnit\Framework\Test $test
121 * @param \Exception $e
124 public function addIncompleteTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
126 ->writeNotOk($test, '', 'TODO Incomplete Test');
132 * @param \PHPUnit\Framework\Test $test
133 * @param \Exception $e
136 * @since Method available since Release 4.0.0
138 public function addRiskyTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
140 ->write(sprintf("ok %d - # RISKY%s\n", $this->testNumber
, $e
141 ->getMessage() != '' ?
' ' . $e
142 ->getMessage() : ''));
143 $this->testSuccessful
= FALSE;
149 * @param \PHPUnit\Framework\Test $test
150 * @param \Exception $e
153 * @since Method available since Release 3.0.0
155 public function addSkippedTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
157 ->write(sprintf("ok %d - # SKIP%s\n", $this->testNumber
, $e
158 ->getMessage() != '' ?
' ' . $e
159 ->getMessage() : ''));
160 $this->testSuccessful
= FALSE;
166 * @param \PHPUnit\Framework\Test $test
167 * @param \PHPUnit\Framework\Warning $e
170 * @since Method available since Release 3.0.0
172 public function addWarning(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\Warning
$e, $time) {
174 ->write(sprintf("ok %d - # Warning%s\n", $this->testNumber
, $e
175 ->getMessage() != '' ?
' ' . $e
176 ->getMessage() : ''));
177 $this->testSuccessful
= FALSE;
181 * A testsuite started.
183 * @param \PHPUnit\Framework\TestSuite $suite
185 public function startTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
186 $this->testSuiteLevel++
;
192 * @param \PHPUnit\Framework\TestSuite $suite
194 public function endTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
195 $this->testSuiteLevel
--;
196 if ($this->testSuiteLevel
== 0) {
198 ->write(sprintf("1..%d\n", $this->testNumber
));
205 * @param \PHPUnit\Framework\Test $test
207 public function startTest(\PHPUnit\Framework\Test
$test) {
209 $this->testSuccessful
= TRUE;
215 * @param \PHPUnit\Framework\Test $test
218 public function endTest(\PHPUnit\Framework\Test
$test, $time) {
219 if ($this->testSuccessful
=== TRUE) {
221 ->write(sprintf("ok %d - %s\n", $this->testNumber
, \PHPUnit\Util\Test
::describe($test)));
224 ->writeDiagnostics($test);
228 * @param \PHPUnit\Framework\Test $test
229 * @param string $prefix
230 * @param string $directive
232 protected function writeNotOk(\PHPUnit\Framework\Test
$test, $prefix = '', $directive = '') {
234 ->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber
, $prefix != '' ?
$prefix . ': ' : '', \PHPUnit\Util\Test
::describe($test), $directive != '' ?
' # ' . $directive : ''));
235 $this->testSuccessful
= FALSE;
239 * @param \PHPUnit\Framework\Test $test
241 private function writeDiagnostics(\PHPUnit\Framework\Test
$test) {
242 if (!$test instanceof \PHPUnit\Framework\TestCase
) {
249 foreach (explode("\n", trim($test
250 ->getActualOutput())) as $line) {
252 ->write(sprintf("# %s\n", $line));