3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Base class for test listeners that interact with an issue tracker.
14 * @since Class available since Release 3.4.0
16 abstract class PHPUnit_Extensions_TicketListener implements PHPUnit_Framework_TestListener
21 protected $ticketCounts = array();
26 protected $ran = false;
31 * @param PHPUnit_Framework_Test $test
35 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
42 * @param PHPUnit_Framework_Test $test
43 * @param PHPUnit_Framework_AssertionFailedError $e
46 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
53 * @param PHPUnit_Framework_Test $test
57 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
64 * @param PHPUnit_Framework_Test $test
68 * @since Method available since Release 4.0.0
70 public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
77 * @param PHPUnit_Framework_Test $test
81 * @since Method available since Release 3.0.0
83 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
88 * A test suite started.
90 * @param PHPUnit_Framework_TestSuite $suite
92 * @since Method available since Release 2.2.0
94 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
101 * @param PHPUnit_Framework_TestSuite $suite
103 * @since Method available since Release 2.2.0
105 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
112 * @param PHPUnit_Framework_Test $test
114 public function startTest(PHPUnit_Framework_Test $test)
116 if (!$test instanceof PHPUnit_Framework_Warning) {
121 $name = $test->getName(false);
122 $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
124 foreach ($tickets as $ticket) {
125 $this->ticketCounts[$ticket][$name] = 1;
135 * @param PHPUnit_Framework_Test $test
138 public function endTest(PHPUnit_Framework_Test $test, $time)
140 if (!$test instanceof PHPUnit_Framework_Warning) {
141 if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
142 $ifStatus = array('assigned', 'new', 'reopened');
143 $newStatus = 'closed';
144 $message = 'Automatically closed by PHPUnit (test passed).';
145 $resolution = 'fixed';
147 } elseif ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
148 $ifStatus = array('closed');
149 $newStatus = 'reopened';
150 $message = 'Automatically reopened by PHPUnit (test failed).';
157 $name = $test->getName(false);
158 $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
160 foreach ($tickets as $ticket) {
161 // Remove this test from the totals (if it passed).
162 if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
163 unset($this->ticketCounts[$ticket][$name]);
166 // Only close tickets if ALL referenced cases pass
167 // but reopen tickets if a single test fails.
169 // Determine number of to-pass tests:
170 if (count($this->ticketCounts[$ticket]) > 0) {
171 // There exist remaining test cases with this reference.
172 $adjustTicket = false;
174 // No remaining tickets, go ahead and adjust.
175 $adjustTicket = true;
178 $adjustTicket = true;
181 $ticketInfo = $this->getTicketInfo($ticket);
183 if ($adjustTicket && in_array($ticketInfo['status'], $ifStatus)) {
184 $this->updateTicket($ticket, $newStatus, $message, $resolution);
191 * @param mixed $ticketId
195 abstract protected function getTicketInfo($ticketId = null);
198 * @param string $ticketId
199 * @param string $newStatus
200 * @param string $message
201 * @param string $resolution
203 abstract protected function updateTicket($ticketId, $newStatus, $message, $resolution);