~jsitech/jackthestripper/jts.debian8

« back to all changes in this revision

Viewing changes to phpunit-patched/PHPUnit/Runner/BaseTestRunner.php

  • Committer: Jason Soto
  • Date: 2015-06-21 13:57:00 UTC
  • Revision ID: jsitech@localhost.localdomain-20150621135700-6i5sw2i59k2gz0o2
Inicialización Repo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHPUnit
 
4
 *
 
5
 * Copyright (c) 2001-2014, 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 Runner
 
39
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
40
 * @copyright  2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
 
41
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
42
 * @link       http://www.phpunit.de/
 
43
 * @since      File available since Release 2.0.0
 
44
 */
 
45
 
 
46
/**
 
47
 * Base class for all test runners.
 
48
 *
 
49
 * @package    PHPUnit
 
50
 * @subpackage Runner
 
51
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
52
 * @copyright  2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
 
53
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
54
 * @link       http://www.phpunit.de/
 
55
 * @since      Class available since Release 2.0.0
 
56
 */
 
57
abstract class PHPUnit_Runner_BaseTestRunner
 
58
{
 
59
    const STATUS_PASSED     = 0;
 
60
    const STATUS_SKIPPED    = 1;
 
61
    const STATUS_INCOMPLETE = 2;
 
62
    const STATUS_FAILURE    = 3;
 
63
    const STATUS_ERROR      = 4;
 
64
    const SUITE_METHODNAME  = 'suite';
 
65
 
 
66
    /**
 
67
     * Returns the loader to be used.
 
68
     *
 
69
     * @return PHPUnit_Runner_TestSuiteLoader
 
70
     */
 
71
    public function getLoader()
 
72
    {
 
73
        return new PHPUnit_Runner_StandardTestSuiteLoader;
 
74
    }
 
75
 
 
76
    /**
 
77
     * Returns the Test corresponding to the given suite.
 
78
     * This is a template method, subclasses override
 
79
     * the runFailed() and clearStatus() methods.
 
80
     *
 
81
     * @param  string  $suiteClassName
 
82
     * @param  string  $suiteClassFile
 
83
     * @param  mixed   $suffixes
 
84
     * @return PHPUnit_Framework_Test
 
85
     */
 
86
    public function getTest($suiteClassName, $suiteClassFile = '', $suffixes = '')
 
87
    {
 
88
        if (is_dir($suiteClassName) &&
 
89
            !is_file($suiteClassName . '.php') && empty($suiteClassFile)) {
 
90
            $facade = new File_Iterator_Facade;
 
91
            $files  = $facade->getFilesAsArray(
 
92
              $suiteClassName, $suffixes
 
93
            );
 
94
 
 
95
            $suite = new PHPUnit_Framework_TestSuite($suiteClassName);
 
96
            $suite->addTestFiles($files);
 
97
 
 
98
            return $suite;
 
99
        }
 
100
 
 
101
        try {
 
102
            $testClass = $this->loadSuiteClass(
 
103
              $suiteClassName, $suiteClassFile
 
104
            );
 
105
        }
 
106
 
 
107
        catch (Exception $e) {
 
108
            $this->runFailed($e->getMessage());
 
109
            return NULL;
 
110
        }
 
111
 
 
112
        try {
 
113
            $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME);
 
114
 
 
115
            if (!$suiteMethod->isStatic()) {
 
116
                $this->runFailed(
 
117
                  'suite() method must be static.'
 
118
                );
 
119
 
 
120
                return NULL;
 
121
            }
 
122
 
 
123
            try {
 
124
                $test = $suiteMethod->invoke(NULL, $testClass->getName());
 
125
            }
 
126
 
 
127
            catch (ReflectionException $e) {
 
128
                $this->runFailed(
 
129
                  sprintf(
 
130
                    "Failed to invoke suite() method.\n%s",
 
131
 
 
132
                    $e->getMessage()
 
133
                  )
 
134
                );
 
135
 
 
136
                return NULL;
 
137
            }
 
138
        }
 
139
 
 
140
        catch (ReflectionException $e) {
 
141
            try {
 
142
                $test = new PHPUnit_Framework_TestSuite($testClass);
 
143
            }
 
144
 
 
145
            catch (PHPUnit_Framework_Exception $e) {
 
146
                $test = new PHPUnit_Framework_TestSuite;
 
147
                $test->setName($suiteClassName);
 
148
            }
 
149
        }
 
150
 
 
151
        $this->clearStatus();
 
152
 
 
153
        return $test;
 
154
    }
 
155
 
 
156
    /**
 
157
     * Returns the loaded ReflectionClass for a suite name.
 
158
     *
 
159
     * @param  string  $suiteClassName
 
160
     * @param  string  $suiteClassFile
 
161
     * @return ReflectionClass
 
162
     */
 
163
    protected function loadSuiteClass($suiteClassName, $suiteClassFile = '')
 
164
    {
 
165
        $loader = $this->getLoader();
 
166
 
 
167
        if ($loader instanceof PHPUnit_Runner_StandardTestSuiteLoader) {
 
168
            return $loader->load($suiteClassName, $suiteClassFile);
 
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
}