Completed
Branch master (d4e26c)
by Tim
01:59
created

TestSuiteFactory::invokeTestSuite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestSuiteFactory extends TestCaseFactory
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
    public 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
    public function invokeTestSuite()
78
    {
79
        $this->invokeTest();
80
    }
81
82
    abstract public function invokeTest();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
83
}
84