Passed
Push — master ( 2ee37f...93876b )
by Tim
02:23
created

TestResult::setCategory()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
final class TestResult
6
{
7
    /**
8
     * @var int     The state reflecting the result
9
     */
10
    private $state;
11
12
    /**
13
     * @var string  Test category this test belongs to
14
     */
15
    private $category;
16
17
    /**
18
     * @var string  The subject that was tested
19
     */
20
    private $subject;
21
22
    /**
23
     * @var string  Message describing the result
24
     */
25
    private $message;
26
27
    /**
28
     * @var array   Data to be used by TestSuite or other TestCases
29
     */
30
    private $output;
31
32
    /**
33
     * @param string $category
34
     * @param string $subject
35
     */
36
    public function __construct($category = 'Unknown category', $subject = 'Unknown subject')
37
    {
38
        $this->setCategory($category);
39
        $this->setSubject($subject);
40
        $this->setOutput(array());
41
        $this->setState(State::NOSTATE);
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function arrayizeTestResult()
48
    {
49
        return array(
50
            $this->getState(),
51
            $this->getCategory(),
52
            $this->getSubject(),
53
            $this->getMessage(),
54
            $this->getOutput()
55
        );
56
    }
57
58
    /**
59
     * @param string $subject
60
     *
61
     * @return void
62
     */
63
    public function setSubject($subject)
64
    {
65
        assert(is_string($subject));
66
        $this->subject = $subject;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getSubject()
73
    {
74
        assert(is_string($this->subject));
75
        return $this->subject;
76
    }
77
78
    /**
79
     * @param string $category
80
     *
81
     * @return void
82
     */
83
    public function setCategory($category)
84
    {
85
        assert(is_string($category));
86
        $this->category = $category;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getCategory()
93
    {
94
        assert(is_string($this->category));
95
        return $this->category;
96
    }
97
98
    /**
99
     * @param string $message
100
     *
101
     * @return void
102
     */
103
    public function setMessage($message)
104
    {
105
        assert(is_string($message));
106
        $this->message = $message;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getMessage()
113
    {
114
        assert(is_string($this->message));
115
        return $this->message;
116
    }
117
118
    /**
119
     * @param array $value
120
     *
121
     * @return void
122
     */
123
    public function setOutput($value)
124
    {
125
        assert(is_array($value));
126
        $this->output = $value;
127
    }
128
129
    /**
130
     * @param mixed $value
131
     * @param string|null $index
132
     *
133
     * @return void
134
     */
135
    public function addOutput($value, $index = null)
136
    {
137
        if ($index === null) {
138
            $this->output = array_merge($this->output, $value);
139
        } else {
140
            $this->output[$index] = $value;
141
        }
142
    }
143
144
    /**
145
     * @param string|null $key
146
     *
147
     * @return mixed
148
     */
149
    public function getOutput($key = null)
150
    {
151
        assert(is_array($this->output));
152
        return is_null($key) ? $this->output : (isSet($this->output[$key]) ? $this->output[$key] : null);
153
    }
154
    
155
    /**
156
     * @param int $state
157
     *
158
     * @return void
159
     */
160
    public function setState($state = State::NOSTATE)
161
    {
162
        assert(is_int($state));
163
        $this->state = $state;
164
    }
165
166
    /**
167
     * @return int
168
     */
169
    public function getState()
170
    {
171
        assert(is_int($this->state));
172
        return $this->state;
173
    }
174
}
175