5 * Copyright (c) 2002-2011, Sebastian Bergmann <sb@sebastian-bergmann.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.
39 * @author Graham Christensen <graham@grahamc.com>
40 * @author Sean Coates <sean@caedmon.net>
41 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
42 * @copyright 2002-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 * @link http://www.phpunit.de/
45 * @since Class available since Release 3.5.4
49 * A ticket listener that interacts with Trac.
54 * <!-- You may need to update the path to the TicketListener -->
55 * <listener class="PHPUnit_Extensions_TicketListener_Trac"
56 * file="/usr/lib/php/PHPUnit/Extensions/TicketListener/Trac.php">
58 * <!-- A user and their password. This user must have XML_RPC permissions -->
59 * <string>trac_username</string>
60 * <string>trac_password</string>
61 * <!-- The URL for your XML-RPC endpoint. -->
62 * <!-- For example, if trac is at 127.0.0.1/trac: -->
63 * <string>127.0.0.1/trac/login/xmlrpc</string>
72 * @author Graham Christensen <graham@grahamc.com>
73 * @author Sean Coates <sean@caedmon.net>
74 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
75 * @copyright 2002-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
76 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
77 * @version Release: 3.5.13
78 * @link http://www.phpunit.de/
79 * @since Class available since Release 3.5.4
81 class PHPUnit_Extensions_TicketListener_Trac extends PHPUnit_Extensions_TicketListener
87 private $printTicketStateChanges;
92 * @param string $username Trac-XMLRPC username
93 * @param string $password Trac-XMLRPC password
94 * @param string $hostpath Trac-XMLRPC Host+Path (e.g. example.com/trac/login/xmlrpc)
95 * @param string $scheme Trac scheme (http or https)
96 * @param bool $printTicketStateChanges To display changes or not
98 public function __construct($username, $password, $hostpath, $scheme = 'http', $printTicketStateChanges = FALSE)
100 $this->username = $username;
101 $this->password = $password;
102 $this->hostpath = $hostpath;
103 $this->scheme = $scheme;
104 $this->printTicketStateChanges = $printTicketStateChanges;
108 * Get the status of a ticket message
110 * @param integer $ticketId The ticket ID
111 * @return array('status' => $status) ($status = new|closed|unknown_ticket)
113 public function getTicketInfo($ticketId = NULL)
115 if (!is_numeric($ticketId)) {
116 return array('status' => 'invalid_ticket_id');
120 $info = $this->getClient()->get($ticketId);
122 switch ($info[3]['status']) {
124 return array('status' => 'closed');
130 return array('status' => 'new');
135 return array('status' => 'unknown_ticket');
140 catch (Exception $e) {
141 return array('status' => 'unknown_ticket');
146 * Update a ticket with a new status
148 * @param string $ticketId The ticket number of the ticket under test (TUT).
149 * @param string $statusToBe The status of the TUT after running the associated test.
150 * @param string $message The additional message for the TUT.
151 * @param string $resolution The resolution for the TUT.
153 protected function updateTicket($ticketId, $statusToBe, $message, $resolution)
155 $change = array('status' => $statusToBe, 'resolution' => $resolution);
157 $this->getClient()->update((int)$ticketId, $message, $change);
159 if ($this->printTicketStateChanges) {
161 "\nUpdating Trac issue #%d, status: %s\n", $ticketId, $statusToBe
167 * Get a Trac XML_RPC2 client
169 * @return XML_RPC2_Client
171 protected function getClient()
173 if (!PHPUnit_Util_Filesystem::fileExistsInIncludePath('XML/RPC2/Client.php')) {
174 throw new PHPUnit_Framework_Exception('PEAR/XML_RPC2 is not available.');
177 require_once 'XML/RPC2/Client.php';
187 return XML_RPC2_Client::create($url, array('prefix' => 'ticket.'));