Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Runner;
11
 
12
use function is_dir;
13
use function is_file;
14
use function substr;
15
use PHPUnit\Framework\Exception;
16
use PHPUnit\Framework\TestSuite;
17
use ReflectionClass;
18
use ReflectionException;
19
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
20
 
21
/**
22
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
23
 */
24
abstract class BaseTestRunner
25
{
26
    /**
27
     * @var int
28
     */
29
    public const STATUS_UNKNOWN = -1;
30
 
31
    /**
32
     * @var int
33
     */
34
    public const STATUS_PASSED = 0;
35
 
36
    /**
37
     * @var int
38
     */
39
    public const STATUS_SKIPPED = 1;
40
 
41
    /**
42
     * @var int
43
     */
44
    public const STATUS_INCOMPLETE = 2;
45
 
46
    /**
47
     * @var int
48
     */
49
    public const STATUS_FAILURE = 3;
50
 
51
    /**
52
     * @var int
53
     */
54
    public const STATUS_ERROR = 4;
55
 
56
    /**
57
     * @var int
58
     */
59
    public const STATUS_RISKY = 5;
60
 
61
    /**
62
     * @var int
63
     */
64
    public const STATUS_WARNING = 6;
65
 
66
    /**
67
     * @var string
68
     */
69
    public const SUITE_METHODNAME = 'suite';
70
 
71
    /**
72
     * Returns the loader to be used.
73
     */
74
    public function getLoader(): TestSuiteLoader
75
    {
76
        return new StandardTestSuiteLoader;
77
    }
78
 
79
    /**
80
     * Returns the Test corresponding to the given suite.
81
     * This is a template method, subclasses override
82
     * the runFailed() and clearStatus() methods.
83
     *
84
     * @param string|string[] $suffixes
85
     *
86
     * @throws Exception
87
     */
88
    public function getTest(string $suiteClassFile, $suffixes = ''): ?TestSuite
89
    {
90
        if (is_dir($suiteClassFile)) {
91
            /** @var string[] $files */
92
            $files = (new FileIteratorFacade)->getFilesAsArray(
93
                $suiteClassFile,
94
                $suffixes
95
            );
96
 
97
            $suite = new TestSuite($suiteClassFile);
98
            $suite->addTestFiles($files);
99
 
100
            return $suite;
101
        }
102
 
103
        if (is_file($suiteClassFile) && substr($suiteClassFile, -5, 5) === '.phpt') {
104
            $suite = new TestSuite;
105
            $suite->addTestFile($suiteClassFile);
106
 
107
            return $suite;
108
        }
109
 
110
        try {
111
            $testClass = $this->loadSuiteClass(
112
                $suiteClassFile
113
            );
114
        } catch (\PHPUnit\Exception $e) {
115
            $this->runFailed($e->getMessage());
116
 
117
            return null;
118
        }
119
 
120
        try {
121
            $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME);
122
 
123
            if (!$suiteMethod->isStatic()) {
124
                $this->runFailed(
125
                    'suite() method must be static.'
126
                );
127
 
128
                return null;
129
            }
130
 
131
            $test = $suiteMethod->invoke(null, $testClass->getName());
132
        } catch (ReflectionException $e) {
133
            $test = new TestSuite($testClass);
134
        }
135
 
136
        $this->clearStatus();
137
 
138
        return $test;
139
    }
140
 
141
    /**
142
     * Returns the loaded ReflectionClass for a suite name.
143
     */
144
    protected function loadSuiteClass(string $suiteClassFile): ReflectionClass
145
    {
146
        return $this->getLoader()->load($suiteClassFile);
147
    }
148
 
149
    /**
150
     * Clears the status message.
151
     */
152
    protected function clearStatus(): void
153
    {
154
    }
155
 
156
    /**
157
     * Override to define how to handle a failed loading of
158
     * a test suite.
159
     */
160
    abstract protected function runFailed(string $message): void;
161
}