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