~ubuntu-branches/ubuntu/natty/phpunit/natty

« back to all changes in this revision

Viewing changes to PHPUnit-3.5.5/PHPUnit/Util/Log/DBUS.php

  • Committer: Package Import Robot
  • Author(s): Ivan Borzenkov
  • Date: 2010-12-11 18:19:39 UTC
  • mfrom: (0.11.1) (1.5.3) (12.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20101211181939-8650nbu08hf2z9v1
Tags: 3.5.5-2
fix doc-base-file-references-missing-file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHPUnit
 
4
 *
 
5
 * Copyright (c) 2002-2010, 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-2010 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-2010 Sebastian Bergmann <sebastian@phpunit.de>
 
55
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
 
56
 * @version    Release: 3.5.5
 
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
     * An error occurred.
 
99
     *
 
100
     * @param  PHPUnit_Framework_Test $test
 
101
     * @param  Exception              $e
 
102
     * @param  float                  $time
 
103
     */
 
104
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
 
105
    {
 
106
        $this->errors++;
 
107
    }
 
108
 
 
109
    /**
 
110
     * A failure occurred.
 
111
     *
 
112
     * @param  PHPUnit_Framework_Test                 $test
 
113
     * @param  PHPUnit_Framework_AssertionFailedError $e
 
114
     * @param  float                                  $time
 
115
     */
 
116
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 
117
    {
 
118
        $this->failures++;
 
119
    }
 
120
 
 
121
    /**
 
122
     * Incomplete test.
 
123
     *
 
124
     * @param  PHPUnit_Framework_Test $test
 
125
     * @param  Exception              $e
 
126
     * @param  float                  $time
 
127
     */
 
128
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 
129
    {
 
130
    }
 
131
 
 
132
    /**
 
133
     * Skipped test.
 
134
     *
 
135
     * @param  PHPUnit_Framework_Test $test
 
136
     * @param  Exception              $e
 
137
     * @param  float                  $time
 
138
     * @since  Method available since Release 3.0.0
 
139
     */
 
140
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 
141
    {
 
142
    }
 
143
 
 
144
    /**
 
145
     * A test suite started.
 
146
     *
 
147
     * @param  PHPUnit_Framework_TestSuite $suite
 
148
     * @since  Method available since Release 2.2.0
 
149
     */
 
150
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
 
151
    {
 
152
        if($this->startedSuites == 0) {
 
153
            $this->startTime = time();
 
154
            $this->suiteName = $suite->getName();
 
155
        }
 
156
 
 
157
        $this->startedSuites++;
 
158
    }
 
159
 
 
160
    /**
 
161
     * A test suite ended.
 
162
     *
 
163
     * @param  PHPUnit_Framework_TestSuite $suite
 
164
     * @since  Method available since Release 2.2.0
 
165
     */
 
166
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
 
167
    {
 
168
        $this->endedSuites++;
 
169
 
 
170
        if($this->startedSuites <= $this->endedSuites) {
 
171
            $this->notify();
 
172
        }
 
173
    }
 
174
 
 
175
    /**
 
176
     * A test started.
 
177
     *
 
178
     * @param  PHPUnit_Framework_Test $test
 
179
     */
 
180
    public function startTest(PHPUnit_Framework_Test $test)
 
181
    {
 
182
        $this->tests++;
 
183
    }
 
184
 
 
185
    /**
 
186
     * A test ended.
 
187
     *
 
188
     * @param  PHPUnit_Framework_Test $test
 
189
     * @param  float                  $time
 
190
     */
 
191
    public function endTest(PHPUnit_Framework_Test $test, $time)
 
192
    {
 
193
    }
 
194
 
 
195
    /**
 
196
     *
 
197
     */
 
198
    protected function notify()
 
199
    {
 
200
        $d = new Dbus(Dbus::BUS_SESSION);
 
201
 
 
202
        $n = $d->createProxy(
 
203
          'org.freedesktop.Notifications',
 
204
          '/org/freedesktop/Notifications',
 
205
          'org.freedesktop.Notifications'
 
206
        );
 
207
 
 
208
        $n->Notify(
 
209
          'PHPUnit_Util_Log_DBUS',
 
210
          new DBusUInt32(0),
 
211
          'phpunit',
 
212
          'PHPUnit Test Report',
 
213
          sprintf(
 
214
            "Suite: %s\n%d tests run in %s minutes.\n%d errors, %d failures",
 
215
            $this->suiteName,
 
216
            $this->tests,
 
217
            (date('i:s', time() - $this->startTime)),
 
218
            $this->errors,
 
219
            $this->failures
 
220
          ),
 
221
          new DBusArray(DBus::STRING, array()),
 
222
          new DBusDict(DBus::VARIANT, array()),
 
223
          1000
 
224
        );
 
225
    }
 
226
}