|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TonicHealthCheck\Test\Incident\Siren\NotificationType; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
use TonicForHealth\PagerDutyClient\Client\EventClient; |
|
8
|
|
|
use TonicForHealth\PagerDutyClient\Entity\Event\Event; |
|
9
|
|
|
use TonicHealthCheck\Incident\IncidentInterface; |
|
10
|
|
|
use TonicHealthCheck\Incident\Siren\NotificationType\PagerDutyNotificationType; |
|
11
|
|
|
use TonicHealthCheck\Test\Incident\IncidentCreateTrait; |
|
12
|
|
|
use TonicHealthCheck\Test\Incident\Subject\SubjectCreateTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class RequestNotificationTypeTest. |
|
16
|
|
|
*/ |
|
17
|
|
|
class PagerDutyNotificationTypeTest extends PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use SubjectCreateTrait; |
|
20
|
|
|
use IncidentCreateTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var PHPUnit_Framework_MockObject_MockObject|EventClient |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $eventClientMock; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var PagerDutyNotificationType; |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $pagerDutyNType; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $serviceKey; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* set up base env Request type test. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function setUp() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->serviceKey = '5b2fb01f1f2257dbbde64469977261de'; |
|
43
|
|
|
|
|
44
|
|
|
$this->eventClientMock = $this |
|
45
|
|
|
->getMockBuilder(EventClient::class) |
|
46
|
|
|
->disableOriginalConstructor() |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
|
|
49
|
|
|
$this->pagerDutyNType = new PagerDutyNotificationType( |
|
50
|
|
|
$this->eventClientMock, |
|
51
|
|
|
$this->serviceKey |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Test request notify create. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testNotifyCreate() |
|
59
|
|
|
{ |
|
60
|
|
|
self::assertEquals($this->serviceKey, $this->pagerDutyNType->getServiceKey()); |
|
61
|
|
|
|
|
62
|
|
|
$incident = $this->createIncidentMock(); |
|
63
|
|
|
|
|
64
|
|
|
$incident |
|
|
|
|
|
|
65
|
|
|
->expects(self::any()) |
|
66
|
|
|
->method('getStatus') |
|
67
|
|
|
->willReturn(IncidentInterface::STATUS_OK + 1); |
|
68
|
|
|
|
|
69
|
|
|
$incidentOk = $this->createIncidentMock(); |
|
70
|
|
|
|
|
71
|
|
|
$incidentOk |
|
72
|
|
|
->expects(self::any()) |
|
73
|
|
|
->method('getStatus') |
|
74
|
|
|
->willReturn(IncidentInterface::STATUS_OK); |
|
75
|
|
|
|
|
76
|
|
|
$subject = $this->createSubject('target', '* * * * *'); |
|
77
|
|
|
|
|
78
|
|
|
$event = new Event(); |
|
79
|
|
|
$event->serviceKey = $this->serviceKey; |
|
80
|
|
|
$event->description = $incident->getIdent(); |
|
|
|
|
|
|
81
|
|
|
$event->incidentKey = 'hci_0'; |
|
82
|
|
|
$event->details = [ |
|
83
|
|
|
'log' => $incident->getMessage(), |
|
|
|
|
|
|
84
|
|
|
'status' => $incident->getStatus(), |
|
|
|
|
|
|
85
|
|
|
'type' => $incident->getType(), |
|
|
|
|
|
|
86
|
|
|
'id' => $incident->getId(), |
|
|
|
|
|
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
$this->eventClientMock |
|
|
|
|
|
|
90
|
|
|
->expects(self::at(0)) |
|
91
|
|
|
->method('post') |
|
92
|
|
|
->with($event); |
|
93
|
|
|
|
|
94
|
|
|
$event2 = clone $event; |
|
95
|
|
|
$event2->details = null; |
|
96
|
|
|
$event2->description = null; |
|
97
|
|
|
$event2->eventType = Event::EVENT_TYPE_RESOLVE; |
|
98
|
|
|
|
|
99
|
|
|
$this->eventClientMock |
|
100
|
|
|
->expects(self::at(1)) |
|
101
|
|
|
->method('post') |
|
102
|
|
|
->with($event2); |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$this->pagerDutyNType->notify($subject, $incident); |
|
|
|
|
|
|
107
|
|
|
$this->pagerDutyNType->notify($subject, $incidentOk); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Test request notify update. |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testNotifyUpdate() |
|
115
|
|
|
{ |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: