|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TonicHealthCheck\Test\Incident\Siren; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use PHPUnit_Framework_Error_Warning; |
|
7
|
|
|
use PHPUnit_Framework_TestCase; |
|
8
|
|
|
use TonicHealthCheck\Incident\IncidentInterface; |
|
9
|
|
|
use TonicHealthCheck\Incident\Siren\IncidentSiren; |
|
10
|
|
|
use TonicHealthCheck\Incident\Siren\NotificationType\NotificationTypeInterface; |
|
11
|
|
|
use TonicHealthCheck\Incident\Siren\Subject\SubjectCollection; |
|
12
|
|
|
use TonicHealthCheck\Test\Incident\Subject\SubjectCreateTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class IncidentEventSubscriber. |
|
16
|
|
|
*/ |
|
17
|
|
|
class IncidentSirenTest extends PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use SubjectCreateTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var IncidentSiren; |
|
23
|
|
|
*/ |
|
24
|
|
|
private $incidentSiren; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Test constructor create new SubjectCollection if $subjects skiped. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testConstructorNullSubject() |
|
30
|
|
|
{ |
|
31
|
|
|
$nTypeIMock = $this->getMockBuilder(NotificationTypeInterface::class)->getMock(); |
|
32
|
|
|
|
|
33
|
|
|
$this->setIncidentSiren(new IncidentSiren($nTypeIMock)); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf(SubjectCollection::class, $this->getIncidentSiren()->getSubjects()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* test receive update from subject. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testUpdate() |
|
42
|
|
|
{ |
|
43
|
|
|
$nTypeIMock = $this->getMockBuilder(NotificationTypeInterface::class)->getMock(); |
|
44
|
|
|
|
|
45
|
|
|
$subjectC = new SubjectCollection(); |
|
46
|
|
|
|
|
47
|
|
|
$subjectC->add($this->createSubject('target', '* * * * *')); |
|
48
|
|
|
|
|
49
|
|
|
$this->setIncidentSiren(new IncidentSiren($nTypeIMock, $subjectC)); |
|
50
|
|
|
|
|
51
|
|
|
$incidentMock = $this->getMockBuilder(IncidentInterface::class)->getMock(); |
|
52
|
|
|
|
|
53
|
|
|
$this->getIncidentSiren()->update($incidentMock); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* test receive update from subject. |
|
58
|
|
|
* |
|
59
|
|
|
* @expectedException PHPUnit_Framework_Error_Warning |
|
60
|
|
|
* @expectedExceptionMessage Test exception message |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testNotifyCatchException() |
|
63
|
|
|
{ |
|
64
|
|
|
$nTypeIMock = $this->getMockBuilder(NotificationTypeInterface::class)->getMock(); |
|
65
|
|
|
|
|
66
|
|
|
$subjectC = new SubjectCollection(); |
|
67
|
|
|
|
|
68
|
|
|
$subjectC->add($this->createSubject('terget', '* * * * *')); |
|
69
|
|
|
|
|
70
|
|
|
$this->setIncidentSiren(new IncidentSiren($nTypeIMock, $subjectC)); |
|
71
|
|
|
|
|
72
|
|
|
$incidentMock = $this->getMockBuilder(IncidentInterface::class)->getMock(); |
|
73
|
|
|
|
|
74
|
|
|
$errorException = new Exception('Test exception message', 3234); |
|
75
|
|
|
|
|
76
|
|
|
$nTypeIMock->expects($this->once())->method('notify')->willThrowException($errorException); |
|
77
|
|
|
|
|
78
|
|
|
$this->getIncidentSiren()->notify($incidentMock); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return IncidentSiren |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getIncidentSiren() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->incidentSiren; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param IncidentSiren $incidentSiren |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function setIncidentSiren(IncidentSiren $incidentSiren) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->incidentSiren = $incidentSiren; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|