]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/PHPUnit/PHPUnit/Util/Log/DBUS.php
Add .gitignore
[Github/sugarcrm.git] / tests / PHPUnit / PHPUnit / Util / Log / DBUS.php
1 <?php
2 /**
3  * PHPUnit
4  *
5  * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.de>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *
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
18  *     distribution.
19  *
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.
23  *
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.
36  *
37  * @package    PHPUnit
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
45  */
46
47 /**
48  * A TestListener that integrates with DBUS.
49  *
50  * @package    PHPUnit
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
59  */
60 class PHPUnit_Util_Log_DBUS implements PHPUnit_Framework_TestListener
61 {
62     /**
63      * @var integer
64      */
65     protected $errors = 0;
66
67     /**
68      * @var integer
69      */
70     protected $failures = 0;
71
72     /**
73      * @var integer
74      */
75     protected $startTime = NULL;
76
77     /**
78      * @var string
79      */
80     protected $suiteName = '';
81
82     /**
83      * @var integer
84      */
85     protected $tests = 0;
86
87     /**
88      * @var integer
89      */
90     protected $startedSuites = 0;
91
92     /**
93      * @var integer
94      */
95     protected $endedSuites = 0;
96
97     /**
98      *
99      */
100     public function __construct()
101     {
102         if (!extension_loaded('dbus')) {
103             throw new RuntimeException('ext/dbus is not available');
104         }
105     }
106
107     /**
108      * An error occurred.
109      *
110      * @param  PHPUnit_Framework_Test $test
111      * @param  Exception              $e
112      * @param  float                  $time
113      */
114     public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
115     {
116         $this->errors++;
117     }
118
119     /**
120      * A failure occurred.
121      *
122      * @param  PHPUnit_Framework_Test                 $test
123      * @param  PHPUnit_Framework_AssertionFailedError $e
124      * @param  float                                  $time
125      */
126     public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
127     {
128         $this->failures++;
129     }
130
131     /**
132      * Incomplete test.
133      *
134      * @param  PHPUnit_Framework_Test $test
135      * @param  Exception              $e
136      * @param  float                  $time
137      */
138     public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
139     {
140     }
141
142     /**
143      * Skipped test.
144      *
145      * @param  PHPUnit_Framework_Test $test
146      * @param  Exception              $e
147      * @param  float                  $time
148      * @since  Method available since Release 3.0.0
149      */
150     public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
151     {
152     }
153
154     /**
155      * A test suite started.
156      *
157      * @param  PHPUnit_Framework_TestSuite $suite
158      * @since  Method available since Release 2.2.0
159      */
160     public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
161     {
162         if($this->startedSuites == 0) {
163             $this->startTime = time();
164             $this->suiteName = $suite->getName();
165         }
166
167         $this->startedSuites++;
168     }
169
170     /**
171      * A test suite ended.
172      *
173      * @param  PHPUnit_Framework_TestSuite $suite
174      * @since  Method available since Release 2.2.0
175      */
176     public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
177     {
178         $this->endedSuites++;
179
180         if($this->startedSuites <= $this->endedSuites) {
181             $this->notify();
182         }
183     }
184
185     /**
186      * A test started.
187      *
188      * @param  PHPUnit_Framework_Test $test
189      */
190     public function startTest(PHPUnit_Framework_Test $test)
191     {
192         $this->tests++;
193     }
194
195     /**
196      * A test ended.
197      *
198      * @param  PHPUnit_Framework_Test $test
199      * @param  float                  $time
200      */
201     public function endTest(PHPUnit_Framework_Test $test, $time)
202     {
203     }
204
205     /**
206      *
207      */
208     protected function notify()
209     {
210         $d = new Dbus(Dbus::BUS_SESSION);
211
212         $n = $d->createProxy(
213           'org.freedesktop.Notifications',
214           '/org/freedesktop/Notifications',
215           'org.freedesktop.Notifications'
216         );
217
218         $n->Notify(
219           'PHPUnit_Util_Log_DBUS',
220           new DBusUInt32(0),
221           'phpunit',
222           'PHPUnit Test Report',
223           sprintf(
224             "Suite: %s\n%d tests run in %s minutes.\n%d errors, %d failures",
225             $this->suiteName,
226             $this->tests,
227             (date('i:s', time() - $this->startTime)),
228             $this->errors,
229             $this->failures
230           ),
231           new DBusArray(DBus::STRING, array()),
232           new DBusDict(DBus::VARIANT, array()),
233           1000
234         );
235     }
236 }