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.0.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Filter.php';
48
require_once 'PHPUnit/Runner/StandardTestSuiteLoader.php';
49
 
50
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
51
 
52
/**
53
 * Base class for all test runners.
54
 *
55
 * @category   Testing
56
 * @package    PHPUnit
57
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
58
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
59
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
60
 * @version    Release: 3.4.15
61
 * @link       http://www.phpunit.de/
62
 * @since      Class available since Release 2.0.0
63
 */
64
abstract class PHPUnit_Runner_BaseTestRunner
65
{
66
    const STATUS_PASSED     = 0;
67
    const STATUS_SKIPPED    = 1;
68
    const STATUS_INCOMPLETE = 2;
69
    const STATUS_FAILURE    = 3;
70
    const STATUS_ERROR      = 4;
71
    const SUITE_METHODNAME  = 'suite';
72
 
73
    /**
74
     * Returns the loader to be used.
75
     *
76
     * @return PHPUnit_Runner_TestSuiteLoader
77
     */
78
    public function getLoader()
79
    {
80
        return new PHPUnit_Runner_StandardTestSuiteLoader;
81
    }
82
 
83
    /**
84
     * Returns the Test corresponding to the given suite.
85
     * This is a template method, subclasses override
86
     * the runFailed() and clearStatus() methods.
87
     *
88
     * @param  string  $suiteClassName
89
     * @param  string  $suiteClassFile
90
     * @param  boolean $syntaxCheck
91
     * @return PHPUnit_Framework_Test
92
     */
93
    public function getTest($suiteClassName, $suiteClassFile = '', $syntaxCheck = FALSE)
94
    {
95
        if (is_dir($suiteClassName) &&
96
            !is_file($suiteClassName . '.php') && empty($suiteClassFile)) {
97
            $testCollector = new PHPUnit_Runner_IncludePathTestCollector(
98
              array($suiteClassName)
99
            );
100
 
101
            $suite = new PHPUnit_Framework_TestSuite($suiteClassName);
102
            $suite->addTestFiles($testCollector->collectTests(), $syntaxCheck);
103
 
104
            return $suite;
105
        }
106
 
107
        try {
108
            $testClass = $this->loadSuiteClass(
109
              $suiteClassName, $suiteClassFile, $syntaxCheck
110
            );
111
        }
112
 
113
        catch (Exception $e) {
114
            $this->runFailed($e->getMessage());
115
            return NULL;
116
        }
117
 
118
        try {
119
            $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME);
120
 
121
            if (!$suiteMethod->isStatic()) {
122
                $this->runFailed(
123
                  'suite() method must be static.'
124
                );
125
 
126
                return NULL;
127
            }
128
 
129
            try {
130
                $test = $suiteMethod->invoke(NULL, $testClass->getName());
131
            }
132
 
133
            catch (ReflectionException $e) {
134
                $this->runFailed(
135
                  sprintf(
136
                    "Failed to invoke suite() method.\n%s",
137
 
138
                    $e->getMessage()
139
                  )
140
                );
141
 
142
                return NULL;
143
            }
144
        }
145
 
146
        catch (ReflectionException $e) {
147
            $test = new PHPUnit_Framework_TestSuite($testClass);
148
        }
149
 
150
        $this->clearStatus();
151
 
152
        return $test;
153
    }
154
 
155
    /**
156
     * Returns the loaded ReflectionClass for a suite name.
157
     *
158
     * @param  string  $suiteClassName
159
     * @param  string  $suiteClassFile
160
     * @param  boolean $syntaxCheck
161
     * @return ReflectionClass
162
     */
163
    protected function loadSuiteClass($suiteClassName, $suiteClassFile = '', $syntaxCheck = FALSE)
164
    {
165
        $loader = $this->getLoader();
166
 
167
        if ($loader instanceof PHPUnit_Runner_StandardTestSuiteLoader) {
168
            return $loader->load($suiteClassName, $suiteClassFile, $syntaxCheck);
169
        } else {
170
            return $loader->load($suiteClassName, $suiteClassFile);
171
        }
172
    }
173
 
174
    /**
175
     * Clears the status message.
176
     *
177
     */
178
    protected function clearStatus()
179
    {
180
    }
181
 
182
    /**
183
     * Override to define how to handle a failed loading of
184
     * a test suite.
185
     *
186
     * @param  string  $message
187
     */
188
    abstract protected function runFailed($message);
189
}
190
?>