|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Overwatch\ResultBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Overwatch\ResultBundle\Entity\TestResult; |
|
6
|
|
|
use Overwatch\ResultBundle\Enum\ResultStatus; |
|
7
|
|
|
use Overwatch\TestBundle\Entity\Test; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* TestResultTest |
|
11
|
|
|
* A unit test for the TestResult Entity |
|
12
|
|
|
*/ |
|
13
|
|
|
class TestResultTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $test; |
|
16
|
|
|
|
|
17
|
|
|
private $result; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->test = new Test; |
|
22
|
|
|
$this->test |
|
23
|
|
|
->setName('A test for testing') |
|
24
|
|
|
; |
|
25
|
|
|
|
|
26
|
|
|
$this->result = new TestResult(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testValid() |
|
30
|
|
|
{ |
|
31
|
|
|
$status = ResultStatus::PASSED; |
|
32
|
|
|
$info = 'Bacon ipsum dolor amet kielbasa beef ribs beef venison.'; |
|
33
|
|
|
|
|
34
|
|
|
$this->result |
|
35
|
|
|
->setTest($this->test) |
|
36
|
|
|
->setStatus($status) |
|
37
|
|
|
->setInfo($info) |
|
38
|
|
|
->setCreatedAt(); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertEquals($this->test, $this->result->getTest()); |
|
41
|
|
|
$this->assertEquals($status, $this->result->getStatus()); |
|
42
|
|
|
$this->assertEquals($info, $this->result->getInfo()); |
|
43
|
|
|
$this->assertInstanceOf('\DateTime', $this->result->getCreatedAt()); |
|
44
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
45
|
|
|
json_encode([ |
|
46
|
|
|
'id' => null, |
|
47
|
|
|
'status' => $status, |
|
48
|
|
|
'info' => $info, |
|
49
|
|
|
'createdAt' => $this->result->getCreatedAt()->getTimestamp(), |
|
50
|
|
|
]), |
|
51
|
|
|
json_encode($this->result) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @expectedException \InvalidArgumentException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testInvalidStatus() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->result->setStatus('IfThisStatusExistsIBrokeIt'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testCreatedAtIsImmutable() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->result->setCreatedAt(); |
|
66
|
|
|
$expected = $this->result->getCreatedAt(); |
|
67
|
|
|
|
|
68
|
|
|
$this->result->setCreatedAt(); |
|
69
|
|
|
$this->assertEquals($expected, $this->result->getCreatedAt()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testSetInfoConvertsExceptions() |
|
73
|
|
|
{ |
|
74
|
|
|
$message = 'Bacon ipsum dolor amet fatback nostrud beef venison mollit officia.'; |
|
75
|
|
|
$this->result->setInfo(new \Exception($message)); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertNotInstanceOf('\Exception', $this->result->getInfo()); |
|
78
|
|
|
$this->assertEquals($message, $this->result->getInfo()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testIsAChange() |
|
82
|
|
|
{ |
|
83
|
|
|
$oldResult = new TestResult(); |
|
84
|
|
|
$oldResult |
|
85
|
|
|
->setStatus(ResultStatus::PASSED) |
|
86
|
|
|
->setTest($this->test); |
|
87
|
|
|
$this->test->addResult($oldResult); |
|
88
|
|
|
|
|
89
|
|
|
$this->result |
|
90
|
|
|
->setStatus(ResultStatus::PASSED) |
|
91
|
|
|
->setTest($this->test); |
|
92
|
|
|
$this->test->addResult($this->result); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertFalse($this->result->isAChange()); |
|
95
|
|
|
|
|
96
|
|
|
$newResult = new TestResult(); |
|
97
|
|
|
$newResult |
|
98
|
|
|
->setStatus(ResultStatus::UNSATISFACTORY) |
|
99
|
|
|
->setTest($this->test); |
|
100
|
|
|
$this->test->addResult($newResult); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertTrue($newResult->isAChange()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testIsAChangeNoTest() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->assertTrue($this->result->isAChange()); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testIsAChangeFirstResult() |
|
111
|
|
|
{ |
|
112
|
|
|
$this->result |
|
113
|
|
|
->setTest($this->test); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertTrue($this->result->isAChange()); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|