1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestSuite\Modules; |
4
|
|
|
|
5
|
|
|
use \SimpleSAML\Module\monitor\State as State; |
6
|
|
|
use \SimpleSAML\Module\monitor\TestCase as TestCase; |
7
|
|
|
use \SimpleSAML\Module\monitor\TestData as TestData; |
8
|
|
|
|
9
|
|
|
final class ModuleSet extends \SimpleSAML\Module\monitor\TestSuiteFactory |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $required; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $available; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $dependencies; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $type; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var TestCase |
33
|
|
|
*/ |
34
|
|
|
private $testCase; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param TestData $testData |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
protected function initialize($testData) |
42
|
|
|
{ |
43
|
|
|
$this->setRequired($testData->getInput('required')); |
44
|
|
|
$this->setAvailable($testData->getInput('available')); |
45
|
|
|
$this->setDependencies($testData->getInput('dependencies')); |
46
|
|
|
$this->setType($testData->getInput('type')); |
47
|
|
|
$this->setTestCase($testData->getInput('testCase')); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array |
52
|
|
|
*/ |
53
|
|
|
private function setRequired($required) |
54
|
|
|
{ |
55
|
|
|
assert(is_array($required)); |
56
|
|
|
$this->required = $required; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param array |
62
|
|
|
*/ |
63
|
|
|
private function setAvailable($available) |
64
|
|
|
{ |
65
|
|
|
assert(is_array($available)); |
66
|
|
|
$this->available = $available; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param array |
72
|
|
|
*/ |
73
|
|
|
private function setDependencies($dependencies) |
74
|
|
|
{ |
75
|
|
|
assert(is_array($dependencies)); |
76
|
|
|
$this->dependencies = $dependencies; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string |
82
|
|
|
*/ |
83
|
|
|
private function setType($type) |
84
|
|
|
{ |
85
|
|
|
assert(is_string($type)); |
86
|
|
|
$this->type = $type; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param TestCase |
92
|
|
|
*/ |
93
|
|
|
private function setTestCase($testCase) |
94
|
|
|
{ |
95
|
|
|
assert($testCase instanceof TestCase); |
|
|
|
|
96
|
|
|
$this->testCase = $testCase; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
protected function invokeTestSuite() |
104
|
|
|
{ |
105
|
|
|
$testResult = new TestResult($this->type, implode(', ', $this->required)); |
106
|
|
|
|
107
|
|
|
if (empty($this->available)) { |
108
|
|
|
$testResult->setState(State::SKIPPED); |
109
|
|
|
} else { |
110
|
|
|
foreach ($this->required as $module) { |
111
|
|
|
$testData = new TestData([ |
112
|
|
|
'required' => $module, |
113
|
|
|
'available' => $this->available |
114
|
|
|
]); |
115
|
|
|
|
116
|
|
|
$moduleTest = new $this->testCase($this, $testData); |
117
|
|
|
$moduleTestResult = $moduleTest->getTestResult(); |
118
|
|
|
if ($moduleTestResult->getState() !== State::OK) { |
119
|
|
|
$missing = array(); |
120
|
|
|
while ($dependency = array_search($this->required, $this->dependencies)) { |
121
|
|
|
if (\SimpleSAML\Module::isModuleEnabled($dependency)) { |
122
|
|
|
$missing[] = $dependency; |
123
|
|
|
} |
124
|
|
|
unset($dependencies[$dependency]); |
125
|
|
|
} |
126
|
|
|
if (!empty($missing)) { |
127
|
|
|
$moduleTestResult->setSubject($moduleTest->getModuleName()); |
128
|
|
|
$moduleTestResult->setMessage('Module not loaded; dependency for ' . implode(', ', $missing)); |
129
|
|
|
} |
130
|
|
|
$this->addTestResult($moduleTestResult); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
$this->calculateState(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$state = $this->getState(); |
137
|
|
View Code Duplication |
if ($state === State::OK) { |
|
|
|
|
138
|
|
|
$testResult->setMessage('All required modules are loaded'); |
139
|
|
|
} elseif ($state === State::SKIPPED) { |
140
|
|
|
$testResult->setMessage('Unable to verify installed modules'); |
141
|
|
|
} else { |
142
|
|
|
$testResult->setMessage('Not all required modules are loaded'); |
143
|
|
|
} |
144
|
|
|
$this->setTestResult($testResult); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.