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 Benjamin Eberlei <kontakt@beberlei.de>
40 * @author Sebastian Bergmann <sebastian@phpunit.de>
41 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.5.0
48 * A TestListener that integrates with DBUS.
51 * @subpackage Util_Log
52 * @author Benjamin Eberlei <kontakt@beberlei.de>
53 * @author Sebastian Bergmann <sebastian@phpunit.de>
54 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
55 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
56 * @version Release: 3.5.13
57 * @link http://www.phpunit.de/
58 * @since Class available since Release 3.5.0
60 class PHPUnit_Util_Log_DBUS implements PHPUnit_Framework_TestListener
65 protected $errors = 0;
70 protected $failures = 0;
75 protected $startTime = NULL;
80 protected $suiteName = '';
90 protected $startedSuites = 0;
95 protected $endedSuites = 0;
100 public function __construct()
102 if (!extension_loaded('dbus')) {
103 throw new RuntimeException('ext/dbus is not available');
110 * @param PHPUnit_Framework_Test $test
111 * @param Exception $e
114 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
120 * A failure occurred.
122 * @param PHPUnit_Framework_Test $test
123 * @param PHPUnit_Framework_AssertionFailedError $e
126 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
134 * @param PHPUnit_Framework_Test $test
135 * @param Exception $e
138 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
145 * @param PHPUnit_Framework_Test $test
146 * @param Exception $e
148 * @since Method available since Release 3.0.0
150 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
155 * A test suite started.
157 * @param PHPUnit_Framework_TestSuite $suite
158 * @since Method available since Release 2.2.0
160 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
162 if($this->startedSuites == 0) {
163 $this->startTime = time();
164 $this->suiteName = $suite->getName();
167 $this->startedSuites++;
171 * A test suite ended.
173 * @param PHPUnit_Framework_TestSuite $suite
174 * @since Method available since Release 2.2.0
176 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
178 $this->endedSuites++;
180 if($this->startedSuites <= $this->endedSuites) {
188 * @param PHPUnit_Framework_Test $test
190 public function startTest(PHPUnit_Framework_Test $test)
198 * @param PHPUnit_Framework_Test $test
201 public function endTest(PHPUnit_Framework_Test $test, $time)
208 protected function notify()
210 $d = new Dbus(Dbus::BUS_SESSION);
212 $n = $d->createProxy(
213 'org.freedesktop.Notifications',
214 '/org/freedesktop/Notifications',
215 'org.freedesktop.Notifications'
219 'PHPUnit_Util_Log_DBUS',
222 'PHPUnit Test Report',
224 "Suite: %s\n%d tests run in %s minutes.\n%d errors, %d failures",
227 (date('i:s', time() - $this->startTime)),
231 new DBusArray(DBus::STRING, array()),
232 new DBusDict(DBus::VARIANT, array()),