Completed
Push — master ( a13755...ce7f01 )
by Tim
01:58
created

TestSuiteFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 4 1
A __construct() 0 9 3
A addTestResult() 0 5 1
A getTestResults() 0 5 1
A calculateState() 0 14 3
invokeTestSuite() 0 1 ?
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestSuiteFactory extends TestFactory
6
{
7
    /**
8
     * @var array
9
     */
10
    private $testResults = array();
11
12
    /**
13
     * @param TestConfiguration|null $configuration
14
     * @param TestData|null $testData
15
     */
16
    public function __construct($configuration = null, $testData = null)
17
    {
18
        assert($configuration instanceof TestConfiguration || is_null($configuration));
19
        assert($testData instanceof TestData || is_null($testData));
20
21
        $this->setConfiguration($configuration);
22
        $this->initialize($testData);
23
        $this->invokeTestSuite();
24
    }
25
26
    /**
27
     * @param TestData|null $testData
28
     *
29
     * @return void
30
     */
31
    protected function initialize($testData = null)
32
    {
33
        $this->setTestData($testData);
34
    }
35
36
    /**
37
     * @param TestResult $testResult
38
     *
39
     * @return void
40
     */
41
    protected function addTestResult($testResult)
42
    {
43
        assert($testResult instanceof TestResult);
44
        $this->testResults[] = $testResult;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getTestResults()
51
    {
52
        assert(is_array($this->testResults));
53
        return $this->testResults;
54
    }
55
56
    /**
57
     * @return State
58
     */
59
    protected function calculateState()
60
    {
61
        $testResults = $this->getTestResults();
62
        $state = State::NOSTATE;
63
64
        if (!empty($testResults)) {
65
            $overall = array();
66
            foreach ($testResults as $testResult) {
67
                $overall[] = $testResult->getState();
68
            }
69
            $state = min($overall);
70
        }
71
        return $state;
72
    }
73
74
    /**
75
     * @return void
76
     */
77
    abstract protected function invokeTestSuite();
78
}
79