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 3.0.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Filter.php';
48
require_once 'PHPUnit/Util/Printer.php';
49
require_once 'PHPUnit/Util/Test.php';
50
 
51
if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('SymfonyComponents/YAML/sfYamlDumper.php')) {
52
    require_once 'SymfonyComponents/YAML/sfYamlDumper.php';
53
}
54
 
55
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
56
 
57
/**
58
 * A TestListener that generates a logfile of the
59
 * test execution using the Test Anything Protocol (TAP).
60
 *
61
 * @category   Testing
62
 * @package    PHPUnit
63
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
64
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
65
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
66
 * @version    Release: 3.4.15
67
 * @link       http://www.phpunit.de/
68
 * @since      Class available since Release 3.0.0
69
 */
70
class PHPUnit_Util_Log_TAP extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
71
{
72
    /**
73
     * @var    integer
74
     */
75
    protected $testNumber = 0;
76
 
77
    /**
78
     * @var    integer
79
     */
80
    protected $testSuiteLevel = 0;
81
 
82
    /**
83
     * @var    boolean
84
     */
85
    protected $testSuccessful = TRUE;
86
 
87
    /**
88
     * Constructor.
89
     *
90
     * @param  mixed $out
91
     * @throws InvalidArgumentException
92
     * @since  Method available since Release 3.3.4
93
     */
94
    public function __construct($out = NULL)
95
    {
96
        parent::__construct($out);
97
        $this->write("TAP version 13\n");
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->writeNotOk($test, 'Error');
110
    }
111
 
112
    /**
113
     * A failure occurred.
114
     *
115
     * @param  PHPUnit_Framework_Test                 $test
116
     * @param  PHPUnit_Framework_AssertionFailedError $e
117
     * @param  float                                  $time
118
     */
119
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
120
    {
121
        $this->writeNotOk($test, 'Failure');
122
 
123
        $message = explode(
124
          "\n", PHPUnit_Framework_TestFailure::exceptionToString($e)
125
        );
126
 
127
        $diagnostic = array(
128
          'message'  => $message[0],
129
          'severity' => 'fail'
130
        );
131
 
132
        if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
133
            $cf = $e->getComparisonFailure();
134
 
135
            if ($cf !== NULL) {
136
                $diagnostic['data'] = array(
137
                  'got'      => $cf->getActual(),
138
                  'expected' => $cf->getExpected()
139
                );
140
            }
141
        }
142
 
143
        if (class_exists('sfYamlDumper')) {
144
            $yaml = new sfYamlDumper;
145
 
146
            $this->write(
147
              sprintf(
148
                "  ---\n%s  ...\n",
149
                $yaml->dump($diagnostic, 2, 2)
150
              )
151
            );
152
        }
153
    }
154
 
155
    /**
156
     * Incomplete test.
157
     *
158
     * @param  PHPUnit_Framework_Test $test
159
     * @param  Exception              $e
160
     * @param  float                  $time
161
     */
162
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
163
    {
164
        $this->writeNotOk($test, '', 'TODO Incomplete Test');
165
    }
166
 
167
    /**
168
     * Skipped test.
169
     *
170
     * @param  PHPUnit_Framework_Test $test
171
     * @param  Exception              $e
172
     * @param  float                  $time
173
     * @since  Method available since Release 3.0.0
174
     */
175
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
176
    {
177
        $this->write(
178
          sprintf(
179
            "ok %d - # SKIP%s\n",
180
 
181
            $this->testNumber,
182
            $e->getMessage() != '' ? ' ' . $e->getMessage() : ''
183
          )
184
        );
185
 
186
        $this->testSuccessful = FALSE;
187
    }
188
 
189
    /**
190
     * A testsuite started.
191
     *
192
     * @param  PHPUnit_Framework_TestSuite $suite
193
     */
194
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
195
    {
196
        $this->testSuiteLevel++;
197
    }
198
 
199
    /**
200
     * A testsuite ended.
201
     *
202
     * @param  PHPUnit_Framework_TestSuite $suite
203
     */
204
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
205
    {
206
        $this->testSuiteLevel--;
207
 
208
        if ($this->testSuiteLevel == 0) {
209
            $this->write(sprintf("1..%d\n", $this->testNumber));
210
        }
211
    }
212
 
213
    /**
214
     * A test started.
215
     *
216
     * @param  PHPUnit_Framework_Test $test
217
     */
218
    public function startTest(PHPUnit_Framework_Test $test)
219
    {
220
        $this->testNumber++;
221
        $this->testSuccessful = TRUE;
222
    }
223
 
224
    /**
225
     * A test ended.
226
     *
227
     * @param  PHPUnit_Framework_Test $test
228
     * @param  float                  $time
229
     */
230
    public function endTest(PHPUnit_Framework_Test $test, $time)
231
    {
232
        if ($this->testSuccessful === TRUE) {
233
            $this->write(
234
              sprintf(
235
                "ok %d - %s\n",
236
 
237
                $this->testNumber,
238
                PHPUnit_Util_Test::describe($test)
239
              )
240
            );
241
        }
242
    }
243
 
244
    /**
245
     * @param  PHPUnit_Framework_Test $test
246
     * @param  string                 $prefix
247
     * @param  string                 $directive
248
     */
249
    protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '')
250
    {
251
        $this->write(
252
          sprintf(
253
            "not ok %d - %s%s%s\n",
254
 
255
            $this->testNumber,
256
            $prefix != '' ? $prefix . ': ' : '',
257
            PHPUnit_Util_Test::describe($test),
258
            $directive != '' ? ' # ' . $directive : ''
259
          )
260
        );
261
 
262
        $this->testSuccessful = FALSE;
263
    }
264
}
265
?>