Completed
Branch feature-unit-tests (9d0273)
by Tim
01:44
created

Monitor   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeAuthSourceCheck() 0 6 1
A getState() 0 4 2
A invokeMetadataCheck() 0 6 1
A invokeTestSuites() 0 7 1
A getResults() 0 3 1
A invokeModuleCheck() 0 5 1
A invokeStoreCheck() 0 5 1
A invokeConfigurationCheck() 0 5 1
A __construct() 0 3 1
A setTestConfiguration() 0 4 1
A getTestConfiguration() 0 4 1
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
class Monitor
6
{
7
    /**
8
     * @var TestConfiguration
9
     */
10
    private $configuration;
11
12
    /**
13
     * @var array
14
     */
15
    private $results = array();
16
17
    /**
18
     * @var array
19
     */
20
    private $state = array();
21
22
    /**
23
     * @param TestConfiguration $testConfiguration
24
     */
25
    public function __construct($testConfiguration)
26
    {
27
        $this->setTestConfiguration($testConfiguration);
28
    }
29
30
    /**
31
     * @return void
32
     */
33
    public function invokeTestSuites()
34
    {
35
        $this->invokeModuleCheck();
36
        $this->invokeConfigurationCheck();
37
        $this->invokeStoreCheck();
38
        $this->invokeAuthSourceCheck();
39
        $this->invokeMetadataCheck();
40
    }
41
42
    /**
43
     * @return TestConfiguration
44
     */
45
    public function getTestConfiguration()
46
    {
47
        assert($this->configuration instanceof TestConfiguration);
48
        return $this->configuration;
49
    }
50
51
    /**
52
     * @param TestConfiguration $testConfiguration
53
     */
54
    private function setTestConfiguration($testConfiguration)
55
    {
56
        assert($testConfiguration instanceof TestConfiguration);
57
        $this->configuration = $testConfiguration;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getResults()
64
    {
65
        return $this->results;
66
    }
67
68
    /**
69
     * @return integer
70
     */
71
    public function getState()
72
    {
73
        $filtered = array_diff($this->state, array(State::SKIPPED));
74
        return empty($filtered) ? State::NOSTATE : min($filtered);
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    private function invokeModuleCheck()
81
    {
82
        $testsuite = new TestSuite\Modules($this->configuration);
83
        $this->results['modules'] = $testsuite->getArrayizeTestResults();
84
        $this->state[] = $testsuite->calculateState();
85
    }
86
87
    /**
88
     * @return void
89
     */
90
    private function invokeConfigurationCheck()
91
    {
92
        $testsuite = new TestSuite\Configuration($this->configuration);
93
        $this->results['configuration'] = $testsuite->getArrayizeTestResults();
94
        $this->state[] = $testsuite->calculateState();
95
    }
96
97
    /**
98
     * @return void
99
     */
100
    private function invokeStoreCheck()
101
    {
102
        $testsuite = new TestSuite\Store($this->configuration);
103
        $this->results['store'] = $testsuite->getArrayizeTestResults();
104
        $this->state[] = $testsuite->calculateState();
105
    }
106
107
    /**
108
     * @return void
109
     */
110
    private function invokeAuthSourceCheck()
111
    {
112
        $testsuite = new TestSuite\AuthSources($this->configuration);
113
        $testResult = $testsuite->getTestResult();
114
        $this->state[] = $testsuite->calculateState();
115
        $this->results['authsources'] = $testResult->getOutput();
116
    }
117
118
    /**
119
     * @return void
120
     */
121
    private function invokeMetadataCheck()
122
    {
123
        $testsuite = new TestSuite\Metadata($this->configuration);
124
        $testResult = $testsuite->getTestResult();
125
        $this->state[] = $testsuite->calculateState();
126
        $this->results['metadata'] = $testResult->getOutput();
127
    }
128
}
129