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 if (version_compare(\PHPUnit\Runner\Version
::id(), '7.0.0', '<')) {
30 class_alias('Civi\Test\TAPLegacy', 'Civi\Test\TAP');
33 class TAP
extends \PHPUnit\Util\Printer
implements \PHPUnit\Framework\TestListener
{
38 protected $testNumber = 0;
43 protected $testSuiteLevel = 0;
48 protected $testSuccessful = TRUE;
55 * @throws \PHPUnit\Framework\Exception
57 * @since Method available since Release 3.3.4
59 public function __construct($out = NULL) {
60 parent
::__construct($out);
62 ->write("TAP version 13\n");
68 * @param \PHPUnit\Framework\Test $test
69 * @param \Throwable $t
72 public function addError(\PHPUnit\Framework\Test
$test, \Throwable
$t, float $time): void
{
74 ->writeNotOk($test, 'Error');
80 * @param \PHPUnit\Framework\Test $test
81 * @param \PHPUnit\Framework\AssertionFailedError $e
84 public function addFailure(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\AssertionFailedError
$e, float $time): void
{
86 ->writeNotOk($test, 'Failure');
87 $message = explode("\n", \PHPUnit\Framework\TestFailure
::exceptionToString($e));
89 'message' => $message[0],
92 if ($e instanceof \PHPUnit\Framework\ExpectationFailedException
) {
94 ->getComparisonFailure();
96 $diagnostic['data'] = array(
105 if (function_exists('yaml_emit')) {
106 $content = \
yaml_emit($diagnostic, YAML_UTF8_ENCODING
);
107 $content = ' ' . strtr($content, ["\n" => "\n "]);
110 // Any valid JSON document is a valid YAML document.
111 $content = json_encode($diagnostic, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
112 // For closest match, drop outermost {}'s. Realign indentation.
113 $content = substr($content, 0, strrpos($content, "}")) . ' }';
114 $content = ' ' . ltrim($content);
115 $content = sprintf(" ---\n%s\n ...\n", $content);
118 $this->write($content);
124 * @param \PHPUnit\Framework\Test $test
125 * @param \Throwable $t
128 public function addIncompleteTest(\PHPUnit\Framework\Test
$test, \Throwable
$t, float $time): void
{
130 ->writeNotOk($test, '', 'TODO Incomplete Test');
136 * @param \PHPUnit\Framework\Test $test
137 * @param \Throwable $t
140 * @since Method available since Release 4.0.0
142 public function addRiskyTest(\PHPUnit\Framework\Test
$test, \Throwable
$t, float $time): void
{
144 ->write(sprintf("ok %d - # RISKY%s\n", $this->testNumber
, $t
145 ->getMessage() != '' ?
' ' . $t
146 ->getMessage() : ''));
147 $this->testSuccessful
= FALSE;
153 * @param \PHPUnit\Framework\Test $test
154 * @param \Throwable $t
157 * @since Method available since Release 3.0.0
159 public function addSkippedTest(\PHPUnit\Framework\Test
$test, \Throwable
$t, float $time): void
{
161 ->write(sprintf("ok %d - # SKIP%s\n", $this->testNumber
, $t
162 ->getMessage() != '' ?
' ' . $t
163 ->getMessage() : ''));
164 $this->testSuccessful
= FALSE;
170 * @param \PHPUnit\Framework\Test $test
171 * @param \PHPUnit\Framework\Warning $e
174 * @since Method available since Release 3.0.0
176 public function addWarning(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\Warning
$e, float $time): void
{
178 ->write(sprintf("ok %d - # Warning%s\n", $this->testNumber
, $e
179 ->getMessage() != '' ?
' ' . $e
180 ->getMessage() : ''));
181 $this->testSuccessful
= FALSE;
185 * A testsuite started.
187 * @param \PHPUnit\Framework\TestSuite $suite
189 public function startTestSuite(\PHPUnit\Framework\TestSuite
$suite): void
{
190 $this->testSuiteLevel++
;
196 * @param \PHPUnit\Framework\TestSuite $suite
198 public function endTestSuite(\PHPUnit\Framework\TestSuite
$suite): void
{
199 $this->testSuiteLevel
--;
200 if ($this->testSuiteLevel
== 0) {
202 ->write(sprintf("1..%d\n", $this->testNumber
));
209 * @param \PHPUnit\Framework\Test $test
211 public function startTest(\PHPUnit\Framework\Test
$test): void
{
213 $this->testSuccessful
= TRUE;
219 * @param \PHPUnit\Framework\Test $test
222 public function endTest(\PHPUnit\Framework\Test
$test, float $time): void
{
223 if ($this->testSuccessful
=== TRUE) {
225 ->write(sprintf("ok %d - %s\n", $this->testNumber
, \PHPUnit\Util\Test
::describeAsString($test)));
228 ->writeDiagnostics($test);
232 * @param \PHPUnit\Framework\Test $test
233 * @param string $prefix
234 * @param string $directive
236 protected function writeNotOk(\PHPUnit\Framework\Test
$test, $prefix = '', $directive = ''): void
{
238 ->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber
, $prefix != '' ?
$prefix . ': ' : '', \PHPUnit\Util\Test
::describeAsString($test), $directive != '' ?
' # ' . $directive : ''));
239 $this->testSuccessful
= FALSE;
243 * @param \PHPUnit\Framework\Test $test
245 private function writeDiagnostics(\PHPUnit\Framework\Test
$test): void
{
246 if (!$test instanceof \PHPUnit\Framework\TestCase
) {
253 foreach (explode("\n", trim($test
254 ->getActualOutput())) as $line) {
256 ->write(sprintf("# %s\n", $line));