Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.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
 * @category   Testing
38
 * @package    PHPUnit
39
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link       http://www.phpunit.de/
43
 * @since      File available since Release 2.3.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Filter.php';
48
 
49
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
50
 
51
/**
52
 * A TestListener that logs to a PEAR_Log sink.
53
 *
54
 * @category   Testing
55
 * @package    PHPUnit
56
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
57
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
58
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
59
 * @version    Release: 3.4.15
60
 * @link       http://www.phpunit.de/
61
 * @since      Class available since Release 2.1.0
62
 */
63
class PHPUnit_Util_Log_PEAR implements PHPUnit_Framework_TestListener
64
{
65
    /**
66
     * Log.
67
     *
68
     * @var    Log
69
     */
70
    protected $log;
71
 
72
    /**
73
     * @param string $type      The type of concrete Log subclass to use.
74
     *                          Currently, valid values are 'console',
75
     *                          'syslog', 'sql', 'file', and 'mcal'.
76
     * @param string $name      The name of the actually log file, table, or
77
     *                          other specific store to use. Defaults to an
78
     *                          empty string, with which the subclass will
79
     *                          attempt to do something intelligent.
80
     * @param string $ident     The identity reported to the log system.
81
     * @param array  $conf      A hash containing any additional configuration
82
     *                          information that a subclass might need.
83
     * @param int $maxLevel     Maximum priority level at which to log.
84
     */
85
    public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
86
    {
87
        if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) {
88
            PHPUnit_Util_Filesystem::collectStart();
89
            require_once 'Log.php';
90
            $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
91
 
92
            foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
93
                PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
94
            }
95
        } else {
96
            throw new RuntimeException('Log is not available.');
97
        }
98
    }
99
 
100
    /**
101
     * An error occurred.
102
     *
103
     * @param  PHPUnit_Framework_Test $test
104
     * @param  Exception              $e
105
     * @param  float                  $time
106
     */
107
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
108
    {
109
        $this->log->crit(
110
          sprintf(
111
            'Test "%s" failed: %s',
112
 
113
            $test->getName(),
114
            $e->getMessage()
115
          )
116
        );
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->log->err(
129
          sprintf(
130
            'Test "%s" failed: %s',
131
 
132
            $test->getName(),
133
            $e->getMessage()
134
          )
135
        );
136
    }
137
 
138
    /**
139
     * Incomplete test.
140
     *
141
     * @param  PHPUnit_Framework_Test $test
142
     * @param  Exception              $e
143
     * @param  float                  $time
144
     */
145
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
146
    {
147
        $this->log->info(
148
          sprintf(
149
            'Test "%s" incomplete: %s',
150
 
151
            $test->getName(),
152
            $e->getMessage()
153
          )
154
        );
155
    }
156
 
157
    /**
158
     * Skipped test.
159
     *
160
     * @param  PHPUnit_Framework_Test $test
161
     * @param  Exception              $e
162
     * @param  float                  $time
163
     * @since  Method available since Release 3.0.0
164
     */
165
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
166
    {
167
        $this->log->info(
168
          sprintf(
169
            'Test "%s" skipped: %s',
170
 
171
            $test->getName(),
172
            $e->getMessage()
173
          )
174
        );
175
    }
176
 
177
    /**
178
     * A test suite started.
179
     *
180
     * @param  PHPUnit_Framework_TestSuite $suite
181
     * @since  Method available since Release 2.2.0
182
     */
183
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
184
    {
185
        $this->log->info(
186
          sprintf(
187
            'TestSuite "%s" started.',
188
 
189
            $suite->getName()
190
          )
191
        );
192
    }
193
 
194
    /**
195
     * A test suite ended.
196
     *
197
     * @param  PHPUnit_Framework_TestSuite $suite
198
     * @since  Method available since Release 2.2.0
199
     */
200
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
201
    {
202
        $this->log->info(
203
          sprintf(
204
            'TestSuite "%s" ended.',
205
 
206
            $suite->getName()
207
          )
208
        );
209
    }
210
 
211
    /**
212
     * A test started.
213
     *
214
     * @param  PHPUnit_Framework_Test $test
215
     */
216
    public function startTest(PHPUnit_Framework_Test $test)
217
    {
218
        $this->log->info(
219
          sprintf(
220
            'Test "%s" started.',
221
 
222
            $test->getName()
223
          )
224
        );
225
    }
226
 
227
    /**
228
     * A test ended.
229
     *
230
     * @param  PHPUnit_Framework_Test $test
231
     * @param  float                  $time
232
     */
233
    public function endTest(PHPUnit_Framework_Test $test, $time)
234
    {
235
        $this->log->info(
236
          sprintf(
237
            'Test "%s" ended.',
238
 
239
            $test->getName()
240
          )
241
        );
242
    }
243
}
244
?>