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(
100 $yaml = new \Symfony\Component\Yaml\
Dumper();
102 ->write(sprintf(" ---\n%s ...\n", $yaml
103 ->dump($diagnostic, 2, 2)));
109 * @param \PHPUnit\Framework\Test $test
110 * @param \Exception $e
113 public function addIncompleteTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
115 ->writeNotOk($test, '', 'TODO Incomplete Test');
121 * @param \PHPUnit\Framework\Test $test
122 * @param \Exception $e
125 * @since Method available since Release 4.0.0
127 public function addRiskyTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
129 ->write(sprintf("ok %d - # RISKY%s\n", $this->testNumber
, $e
130 ->getMessage() != '' ?
' ' . $e
131 ->getMessage() : ''));
132 $this->testSuccessful
= FALSE;
138 * @param \PHPUnit\Framework\Test $test
139 * @param \Exception $e
142 * @since Method available since Release 3.0.0
144 public function addSkippedTest(\PHPUnit\Framework\Test
$test, \Exception
$e, $time) {
146 ->write(sprintf("ok %d - # SKIP%s\n", $this->testNumber
, $e
147 ->getMessage() != '' ?
' ' . $e
148 ->getMessage() : ''));
149 $this->testSuccessful
= FALSE;
155 * @param \PHPUnit\Framework\Test $test
156 * @param \PHPUnit\Framework\Warning $e
159 * @since Method available since Release 3.0.0
161 public function addWarning(\PHPUnit\Framework\Test
$test, \PHPUnit\Framework\Warning
$e, $time) {
163 ->write(sprintf("ok %d - # Warning%s\n", $this->testNumber
, $e
164 ->getMessage() != '' ?
' ' . $e
165 ->getMessage() : ''));
166 $this->testSuccessful
= FALSE;
170 * A testsuite started.
172 * @param \PHPUnit\Framework\TestSuite $suite
174 public function startTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
175 $this->testSuiteLevel++
;
181 * @param \PHPUnit\Framework\TestSuite $suite
183 public function endTestSuite(\PHPUnit\Framework\TestSuite
$suite) {
184 $this->testSuiteLevel
--;
185 if ($this->testSuiteLevel
== 0) {
187 ->write(sprintf("1..%d\n", $this->testNumber
));
194 * @param \PHPUnit\Framework\Test $test
196 public function startTest(\PHPUnit\Framework\Test
$test) {
198 $this->testSuccessful
= TRUE;
204 * @param \PHPUnit\Framework\Test $test
207 public function endTest(\PHPUnit\Framework\Test
$test, $time) {
208 if ($this->testSuccessful
=== TRUE) {
210 ->write(sprintf("ok %d - %s\n", $this->testNumber
, \PHPUnit\Util\Test
::describe($test)));
213 ->writeDiagnostics($test);
217 * @param \PHPUnit\Framework\Test $test
218 * @param string $prefix
219 * @param string $directive
221 protected function writeNotOk(\PHPUnit\Framework\Test
$test, $prefix = '', $directive = '') {
223 ->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber
, $prefix != '' ?
$prefix . ': ' : '', \PHPUnit\Util\Test
::describe($test), $directive != '' ?
' # ' . $directive : ''));
224 $this->testSuccessful
= FALSE;
228 * @param \PHPUnit\Framework\Test $test
230 private function writeDiagnostics(\PHPUnit\Framework\Test
$test) {
231 if (!$test instanceof \PHPUnit\Framework\TestCase
) {
238 foreach (explode("\n", trim($test
239 ->getActualOutput())) as $line) {
241 ->write(sprintf("# %s\n", $line));