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 Extensions_TicketListener
39 * @author Sean Coates <sean@caedmon.net>
40 * @author Raphael Stolt <raphael.stolt@gmail.com>
41 * @author Sebastian Bergmann <sebastian@phpunit.de>
42 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 * @link http://www.phpunit.de/
45 * @since File available since Release 3.4.0
49 * Base class for test listeners that interact with an issue tracker.
52 * @subpackage Extensions_TicketListener
53 * @author Sean Coates <sean@caedmon.net>
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.13
58 * @link http://www.phpunit.de/
59 * @since Class available since Release 3.4.0
61 abstract class PHPUnit_Extensions_TicketListener implements PHPUnit_Framework_TestListener
66 protected $ticketCounts = array();
71 protected $ran = FALSE;
76 * @param PHPUnit_Framework_Test $test
80 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
87 * @param PHPUnit_Framework_Test $test
88 * @param PHPUnit_Framework_AssertionFailedError $e
91 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
98 * @param PHPUnit_Framework_Test $test
102 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
109 * @param PHPUnit_Framework_Test $test
110 * @param Exception $e
112 * @since Method available since Release 3.0.0
114 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
119 * A test suite started.
121 * @param PHPUnit_Framework_TestSuite $suite
122 * @since Method available since Release 2.2.0
124 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
129 * A test suite ended.
131 * @param PHPUnit_Framework_TestSuite $suite
132 * @since Method available since Release 2.2.0
134 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
141 * @param PHPUnit_Framework_Test $test
143 public function startTest(PHPUnit_Framework_Test $test)
145 if (!$test instanceof PHPUnit_Framework_Warning) {
150 $name = $test->getName(FALSE);
151 $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
153 foreach ($tickets as $ticket) {
154 $this->ticketCounts[$ticket][$name] = 1;
164 * @param PHPUnit_Framework_Test $test
167 public function endTest(PHPUnit_Framework_Test $test, $time)
169 if (!$test instanceof PHPUnit_Framework_Warning) {
170 if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
171 $ifStatus = array('assigned', 'new', 'reopened');
172 $newStatus = 'closed';
173 $message = 'Automatically closed by PHPUnit (test passed).';
174 $resolution = 'fixed';
178 else if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
179 $ifStatus = array('closed');
180 $newStatus = 'reopened';
181 $message = 'Automatically reopened by PHPUnit (test failed).';
190 $name = $test->getName(FALSE);
191 $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
193 foreach ($tickets as $ticket) {
194 // Remove this test from the totals (if it passed).
195 if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
196 unset($this->ticketCounts[$ticket][$name]);
199 // Only close tickets if ALL referenced cases pass
200 // but reopen tickets if a single test fails.
202 // Determine number of to-pass tests:
203 if (count($this->ticketCounts[$ticket]) > 0) {
204 // There exist remaining test cases with this reference.
205 $adjustTicket = FALSE;
207 // No remaining tickets, go ahead and adjust.
208 $adjustTicket = TRUE;
211 $adjustTicket = TRUE;
214 $ticketInfo = $this->getTicketInfo($ticket);
216 if ($adjustTicket && in_array($ticketInfo['status'], $ifStatus)) {
217 $this->updateTicket($ticket, $newStatus, $message, $resolution);
223 abstract protected function getTicketInfo($ticketId = NULL);
224 abstract protected function updateTicket($ticketId, $newStatus, $message, $resolution);