5 * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 * @subpackage Util_Log
39 * @author Sebastian Bergmann <sebastian@phpunit.de>
40 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
42 * @link http://www.phpunit.de/
43 * @since File available since Release 3.0.0
46 require_once 'SymfonyComponents/YAML/sfYamlDumper.php';
49 * A TestListener that generates a logfile of the
50 * test execution using the Test Anything Protocol (TAP).
53 * @subpackage Util_Log
54 * @author Sebastian Bergmann <sebastian@phpunit.de>
55 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
56 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
57 * @version Release: 3.5.14
58 * @link http://www.phpunit.de/
59 * @since Class available since Release 3.0.0
61 class PHPUnit_Util_Log_TAP extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
66 protected $testNumber = 0;
71 protected $testSuiteLevel = 0;
76 protected $testSuccessful = TRUE;
82 * @throws InvalidArgumentException
83 * @since Method available since Release 3.3.4
85 public function __construct($out = NULL)
87 parent::__construct($out);
88 $this->write("TAP version 13\n");
94 * @param PHPUnit_Framework_Test $test
98 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
100 $this->writeNotOk($test, 'Error');
104 * A failure occurred.
106 * @param PHPUnit_Framework_Test $test
107 * @param PHPUnit_Framework_AssertionFailedError $e
110 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
112 $this->writeNotOk($test, 'Failure');
115 "\n", PHPUnit_Framework_TestFailure::exceptionToString($e)
119 'message' => $message[0],
123 if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
124 $cf = $e->getComparisonFailure();
127 $diagnostic['data'] = array(
128 'got' => $cf->getActual(),
129 'expected' => $cf->getExpected()
134 $yaml = new sfYamlDumper();
139 $yaml->dump($diagnostic, 2, 2)
147 * @param PHPUnit_Framework_Test $test
148 * @param Exception $e
151 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
153 $this->writeNotOk($test, '', 'TODO Incomplete Test');
159 * @param PHPUnit_Framework_Test $test
160 * @param Exception $e
162 * @since Method available since Release 3.0.0
164 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
168 "ok %d - # SKIP%s\n",
171 $e->getMessage() != '' ? ' ' . $e->getMessage() : ''
175 $this->testSuccessful = FALSE;
179 * A testsuite started.
181 * @param PHPUnit_Framework_TestSuite $suite
183 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
185 $this->testSuiteLevel++;
191 * @param PHPUnit_Framework_TestSuite $suite
193 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
195 $this->testSuiteLevel--;
197 if ($this->testSuiteLevel == 0) {
198 $this->write(sprintf("1..%d\n", $this->testNumber));
205 * @param PHPUnit_Framework_Test $test
207 public function startTest(PHPUnit_Framework_Test $test)
210 $this->testSuccessful = TRUE;
216 * @param PHPUnit_Framework_Test $test
219 public function endTest(PHPUnit_Framework_Test $test, $time)
221 if ($this->testSuccessful === TRUE) {
227 PHPUnit_Util_Test::describe($test)
234 * @param PHPUnit_Framework_Test $test
235 * @param string $prefix
236 * @param string $directive
238 protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '')
242 "not ok %d - %s%s%s\n",
245 $prefix != '' ? $prefix . ': ' : '',
246 PHPUnit_Util_Test::describe($test),
247 $directive != '' ? ' # ' . $directive : ''
251 $this->testSuccessful = FALSE;