1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TestSuite.php |
5
|
|
|
* |
6
|
|
|
* This middleware will intercept traffic from visitors to |
7
|
|
|
* your website. |
8
|
|
|
* |
9
|
|
|
* PHP version 7.2 |
10
|
|
|
* |
11
|
|
|
* @category Core |
12
|
|
|
* @package RedboxTestSuite |
13
|
|
|
* @author Johnny Mast <[email protected]> |
14
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
15
|
|
|
* @link https://github.com/johnnymast/redbox-testsuite |
16
|
|
|
* @since GIT:1.0 |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Redbox\Testsuite; |
20
|
|
|
|
21
|
|
|
class TestSuite |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Storage to contain the |
25
|
|
|
* tests. |
26
|
|
|
* |
27
|
|
|
* @var \SplObjectStorage |
28
|
|
|
*/ |
29
|
|
|
protected ?\SplObjectStorage $tests = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Test Score counter. |
33
|
|
|
* |
34
|
|
|
* @var int|double |
35
|
|
|
*/ |
36
|
|
|
protected $score = 0; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* TestSuite constructor. |
40
|
|
|
*/ |
41
|
18 |
|
public function __construct() |
42
|
|
|
{ |
43
|
18 |
|
$this->tests = new \SplObjectStorage; |
44
|
18 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Reset the score and rewind |
48
|
|
|
* the tests storage. |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
10 |
|
public function reset() |
53
|
|
|
{ |
54
|
10 |
|
$this->score = 0; |
55
|
10 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Attach a Test or an array of |
59
|
|
|
* Tests to the TestSuite. |
60
|
|
|
* |
61
|
|
|
* @param $info The Test to attach. |
|
|
|
|
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
18 |
|
public function attach($info) |
66
|
|
|
{ |
67
|
18 |
|
if (is_array($info) === true) { |
68
|
8 |
|
foreach ($info as $test) { |
69
|
8 |
|
$this->attach($test); |
70
|
|
|
} |
71
|
|
|
} else { |
72
|
18 |
|
$test = $info; |
73
|
|
|
|
74
|
|
|
// TODO: Allow array of class names and instantiate here |
75
|
|
|
/* |
76
|
|
|
if (is_string($info) === true && class_exists($info) === true) { |
77
|
|
|
$test = new $info(); |
78
|
|
|
} |
79
|
|
|
*/ |
80
|
|
|
|
81
|
18 |
|
if (is_subclass_of($test, Test::class) === false) { |
82
|
2 |
|
throw new \InvalidArgumentException('Test does not extend Test abstract class.'); |
83
|
|
|
} |
84
|
|
|
|
85
|
16 |
|
$this->tests->attach($test); |
|
|
|
|
86
|
|
|
} |
87
|
16 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Detach a given test from the |
91
|
|
|
* TestSuite. |
92
|
|
|
* |
93
|
|
|
* @param Test $test The test to detach. |
|
|
|
|
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
2 |
|
public function detach(Test $test) |
98
|
|
|
{ |
99
|
2 |
|
$this->tests->detach($test); |
100
|
2 |
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Check to see if the TestSuite has a given |
104
|
|
|
* test inside. |
105
|
|
|
* |
106
|
|
|
* @param Test $test The Test to check for. |
|
|
|
|
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
6 |
|
public function has(Test $test) |
111
|
|
|
{ |
112
|
6 |
|
return $this->tests->contains($test); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Run the tests |
117
|
|
|
* |
118
|
|
|
* @return int The number of tests that ran. |
119
|
|
|
*/ |
120
|
10 |
|
public function run(): int |
121
|
|
|
{ |
122
|
10 |
|
$tests_run = 0; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Reset the test results |
126
|
|
|
*/ |
127
|
10 |
|
$this->reset(); |
128
|
|
|
|
129
|
10 |
|
foreach ($this->tests as $test) { |
130
|
10 |
|
$test->run(); |
131
|
10 |
|
$this->score += $test->score->getScore(); |
132
|
10 |
|
$tests_run++; |
133
|
|
|
} |
134
|
|
|
|
135
|
10 |
|
return $tests_run; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Return the test suite score. |
140
|
|
|
* |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
6 |
|
public function getScore() |
144
|
|
|
{ |
145
|
6 |
|
return $this->score; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths