1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TestCase.php |
5
|
|
|
* |
6
|
|
|
* The abstract class for Tests inside the TestSuite. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.4 |
9
|
|
|
* |
10
|
|
|
* @category Core |
11
|
|
|
* @package RedboxTestSuite |
12
|
|
|
* @author Johnny Mast <[email protected]> |
13
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
14
|
|
|
* @link https://github.com/johnnymast/redbox-testsuite |
15
|
|
|
* @since 1.0 |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Redbox\Testsuite; |
19
|
|
|
|
20
|
|
|
use Redbox\Testsuite\Interfaces\ContainerInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Test |
24
|
|
|
* |
25
|
|
|
* @package Redbox\Testsuite |
26
|
|
|
*/ |
27
|
|
|
abstract class TestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Instance that keeps track of the score |
31
|
|
|
* for this test. |
32
|
|
|
* |
33
|
|
|
* @var Score|null |
34
|
|
|
*/ |
35
|
|
|
public ?Score $score = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The name of this TestCase. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private string $name = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test constructor. |
46
|
|
|
* |
47
|
|
|
* Note: Tests cant overwrite the function. |
48
|
|
|
*/ |
49
|
|
|
final function __construct() |
50
|
|
|
{ |
51
|
|
|
if (!isset($this->minscore)) |
52
|
|
|
throw new \LogicException( |
53
|
|
|
get_class($this) . ' must have property $minscore to indicate the lowest reachable score.' |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
if (!isset($this->maxscore)) |
57
|
|
|
throw new \LogicException( |
58
|
|
|
get_class($this) . ' must have property $maxscore to indicate the highestreachable score.' |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->score = new Score($this); |
63
|
|
|
$this->afterCreation(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* This function will be called from within the constructor. |
68
|
|
|
* This allows you to setup some data from within your test. |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
protected function afterCreation() |
73
|
|
|
{ |
74
|
|
|
// Overwrite at will |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Return the name of the test. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getName(): string |
83
|
|
|
{ |
84
|
|
|
return $this->name; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set the test name. |
89
|
|
|
* |
90
|
|
|
* @param string $name The name of the test. |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public function setName(string $name): void |
95
|
|
|
{ |
96
|
|
|
$this->name = $name; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Tests must implement this method to indicate |
101
|
|
|
* the maximum score this test can reach. |
102
|
|
|
* |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
|
|
public function minScore(): int |
106
|
|
|
{ |
107
|
|
|
return $this->minscore; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Tests must implement this method to indicate |
112
|
|
|
* the maximum score this test can reach. |
113
|
|
|
* |
114
|
|
|
* @return int |
115
|
|
|
*/ |
116
|
|
|
public function maxScore(): int |
117
|
|
|
{ |
118
|
|
|
return $this->maxscore; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Tests must implement this method to start |
123
|
|
|
* running their tests. |
124
|
|
|
* |
125
|
|
|
* @param ContainerInterface $container The storage container for the TestSuite. |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
abstract public function run(ContainerInterface $container); |
130
|
|
|
} |
131
|
|
|
|