Failed Conditions
Pull Request — master (#142)
by Zac
04:15
created

Test::setGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Overwatch\TestBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * Test
9
 *
10
 * @ORM\Table(
11
 *   name="Test",
12
 *   uniqueConstraints={
13
 *     @ORM\UniqueConstraint(name="unique_actual_expection", columns={"actual", "expectation"})
14
 *   }
15
 * )
16
 * @ORM\Entity(repositoryClass="Overwatch\TestBundle\Entity\TestRepository")
17
 * @ORM\HasLifecycleCallbacks
18
 */
19
class Test implements \JsonSerializable
20
{
21
    /**
22
     * @var integer
23
     *
24
     * @ORM\Column(name="id", type="integer")
25
     * @ORM\Id
26
     * @ORM\GeneratedValue(strategy="AUTO")
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(name="name", type="string", length=50, unique=true)
34
     */
35
    private $name;
36
37
    /**
38
     * @var string
39
     *
40
     * @ORM\Column(name="actual", type="string", length=100)
41
     */
42
    private $actual;
43
44
    /**
45
     * @var string
46
     *
47
     * @ORM\Column(name="expectation", type="string", length=50)
48
     */
49
    private $expectation;
50
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(name="expected", type="string", length=100, nullable=true)
55
     */
56
    private $expected;
57
    
58
    /**
59
     * @ORM\OneToMany(targetEntity="Overwatch\ResultBundle\Entity\TestResult", mappedBy="test", cascade={"remove"})
60
     */
61
    private $results;
62
    
63
    /**
64
     * @ORM\OneToOne(targetEntity="Overwatch\ResultBundle\Entity\TestResult")
65
     */
66
    private $lastResult;
67
    
68
    /**
69
     * @ORM\ManyToOne(targetEntity="TestGroup", inversedBy="tests")
70
     */
71
    private $group;
72
73
    /**
74
     * @var \DateTime
75
     *
76
     * @ORM\Column(name="created_at", type="datetime")
77
     */
78
    private $createdAt;
79
80
    /**
81
     * @var \DateTime
82
     *
83
     * @ORM\Column(name="updated_at", type="datetime")
84
     */
85
    private $updatedAt;
86
    
87
88
    /**
89
     * Constructor
90
     */
91 22
    public function __construct()
92
    {
93 22
        $this->results = new \Doctrine\Common\Collections\ArrayCollection();
94 22
    }
95
    
96
    /**
97
     * To String
98
     * 
99
     * @return string
100
     */
101 1
    public function __toString()
102
    {
103 1
        return $this->getName();
104
    }
105
    
106
    /**
107
     * Serialise object to JSON
108
     */
109 1
    public function jsonSerialize()
110
    {
111
        return [
112 1
            'id'          => $this->getId(),
113 1
            'name'        => $this->getName(),
114 1
            'actual'      => $this->getActual(),
115 1
            'expectation' => $this->getExpectation(),
116 1
            'expected'    => $this->getExpected(),
117 1
            'result'      => $this->getLastResult(),
118 1
            'createdAt'   => $this->getCreatedAt()->getTimestamp(),
119 1
            'updatedAt'   => $this->getUpdatedAt()->getTimestamp()
120 1
        ];
121
    }
122
    
123
    /**
124
     * Get id
125
     *
126
     * @return integer 
127
     */
128 1
    public function getId()
129
    {
130 1
        return $this->id;
131
    }
132
133
    /**
134
     * Set name
135
     *
136
     * @param string $name
137
     * @return Test
138
     */
139 11
    public function setName($name)
140
    {
141 11
        $this->name = $name;
142
143 11
        return $this;
144
    }
145
146
    /**
147
     * Get name
148
     *
149
     * @return string 
150
     */
151 2
    public function getName()
152
    {
153 2
        return $this->name;
154
    }
155
156
    /**
157
     * Set actual
158
     *
159
     * @param string $actual
160
     * @return Test
161
     */
162 9
    public function setActual($actual)
163
    {
164 9
        $this->actual = $actual;
165
166 9
        return $this;
167
    }
168
169
    /**
170
     * Get actual
171
     *
172
     * @return string 
173
     */
174 6
    public function getActual()
175
    {
176 6
        return $this->actual;
177
    }
178
179
    /**
180
     * Set expectation
181
     *
182
     * @param string $expectation
183
     * @return Test
184
     */
185 9
    public function setExpectation($expectation)
186
    {
187 9
        $this->expectation = $expectation;
188
189 9
        return $this;
190
    }
191
192
    /**
193
     * Get expectation
194
     *
195
     * @return string 
196
     */
197 6
    public function getExpectation()
198
    {
199 6
        return $this->expectation;
200
    }
201
202
    /**
203
     * Set expected
204
     *
205
     * @param string $expected
206
     * @return Test
207
     */
208
    public function setExpected($expected)
209
    {
210
        $this->expected = $expected;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Get expected
217
     *
218
     * @return string 
219
     */
220 6
    public function getExpected()
221
    {
222 6
        return $this->expected;
223
    }
224
225
    /**
226
     * Set createdAt
227
     *
228
     * @ORM\PrePersist
229
     * @return Test
230
     */
231 3
    public function setCreatedAt()
232
    {
233 3
        if ($this->createdAt === null) {
234 3
            $this->createdAt = new \DateTime;
235 3
        }
236
        
237 3
        return $this;
238
    }
239
240
    /**
241
     * Get createdAt
242
     *
243
     * @return \DateTime 
244
     */
245 2
    public function getCreatedAt()
246
    {
247 2
        return $this->createdAt;
248
    }
249
250
    /**
251
     * Set updatedAt
252
     *
253
     * @ORM\PrePersist
254
     * @ORM\PreUpdate
255
     * @return Test
256
     */
257 3
    public function setUpdatedAt()
258
    {
259 3
        $this->updatedAt = new \DateTime;
260
261 3
        return $this;
262
    }
263
264
    /**
265
     * Get updatedAt
266
     *
267
     * @return \DateTime 
268
     */
269 1
    public function getUpdatedAt()
270
    {
271 1
        return $this->updatedAt;
272
    }
273
274
    /**
275
     * Set group
276
     *
277
     * @param \Overwatch\TestBundle\Entity\TestGroup $group
278
     * @return Test
279
     */
280 1
    public function setGroup(\Overwatch\TestBundle\Entity\TestGroup $group = null)
281
    {
282 1
        $this->group = $group;
283
284 1
        return $this;
285
    }
286
287
    /**
288
     * Get group
289
     *
290
     * @return \Overwatch\TestBundle\Entity\TestGroup 
291
     */
292 1
    public function getGroup()
293
    {
294 1
        return $this->group;
295
    }
296
297
    /**
298
     * Add results
299
     *
300
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
301
     * @return Test
302
     */
303 1
    public function addResult(\Overwatch\ResultBundle\Entity\TestResult $result)
304
    {
305 1
        $this->results[] = $result;
306
307 1
        return $this;
308
    }
309
310
    /**
311
     * Remove results
312
     *
313
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
314
     */
315
    public function removeResult(\Overwatch\ResultBundle\Entity\TestResult $result)
316
    {
317
        $this->results->removeElement($result);
318
    }
319
320
    /**
321
     * Get results
322
     *
323
     * @return \Doctrine\Common\Collections\Collection 
324
     */
325 2
    public function getResults()
326
    {
327 2
        return $this->results;
328
    }
329
    
330
    /**
331
     * Set last result
332
     * 
333
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
334
     * @return \Overwatch\TestBundle\Entity\Test
335
     */
336 9
    public function setLastResult(\Overwatch\ResultBundle\Entity\TestResult $result)
337
    {
338 9
        $this->lastResult = $result;
339
        
340 9
        return $this;
341
    }
342
    
343
    /**
344
     * Get last result
345
     * 
346
     * @return \Overwatch\ResultBundle\Entity\TestResult
347
     */
348 1
    public function getLastResult()
349
    {
350 1
        return $this->lastResult;
351
    }
352
}
353