1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of tenside/core. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
12
|
|
|
* |
13
|
|
|
* @package tenside/core |
14
|
|
|
* @author Christian Schiffler <[email protected]> |
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
16
|
|
|
* @license https://github.com/tenside/core/blob/master/LICENSE MIT |
17
|
|
|
* @link https://github.com/tenside/core |
18
|
|
|
* @filesource |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Tenside\Core\SelfTest; |
22
|
|
|
|
23
|
|
|
use Tenside\Core\Config\TensideJsonConfig; |
24
|
|
|
use Tenside\Core\Util\JsonArray; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This class checks that the current environment is suitable for running tenside. |
28
|
|
|
*/ |
29
|
|
|
class SelfTest |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The registered self tests. |
33
|
|
|
* |
34
|
|
|
* @var AbstractSelfTest[] |
35
|
|
|
*/ |
36
|
|
|
private $tests = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The auto configuration. |
40
|
|
|
* |
41
|
|
|
* @var TensideJsonConfig |
42
|
|
|
*/ |
43
|
|
|
private $config; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Create a new instance. |
47
|
|
|
*/ |
48
|
|
|
public function __construct() |
49
|
|
|
{ |
50
|
|
|
$this->config = new TensideJsonConfig(new JsonArray()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Run all tests and return the results as an error array. |
55
|
|
|
* |
56
|
|
|
* @return SelfTestResult[] |
57
|
|
|
*/ |
58
|
|
|
public function perform() |
59
|
|
|
{ |
60
|
|
|
$results = []; |
61
|
|
|
|
62
|
|
|
foreach ($this->tests as $testInstance) { |
63
|
|
|
$results[] = $testInstance->perform($this->config); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $results; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Add a test instance to the list of tests to perform. |
71
|
|
|
* |
72
|
|
|
* @param AbstractSelfTest $test The test to add. |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function addTest(AbstractSelfTest $test) |
77
|
|
|
{ |
78
|
|
|
$this->tests[] = $test; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Retrieve the auto config. |
83
|
|
|
* |
84
|
|
|
* @return TensideJsonConfig |
85
|
|
|
*/ |
86
|
|
|
public function getAutoConfig() |
87
|
|
|
{ |
88
|
|
|
return $this->config; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|