|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TonicHealthCheck\Test\Incident\Siren\NotificationType; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
|
6
|
|
|
use TonicHealthCheck\Incident\IncidentInterface; |
|
7
|
|
|
use TonicHealthCheck\Incident\Siren\NotificationType\FileNotificationType; |
|
8
|
|
|
use TonicHealthCheck\Test\Incident\IncidentCreateTrait; |
|
9
|
|
|
use TonicHealthCheck\Test\Incident\Subject\SubjectCreateTrait; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class FileNotificationTypeTest. |
|
13
|
|
|
*/ |
|
14
|
|
|
class FileNotificationTypeTest extends PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
use SubjectCreateTrait; |
|
17
|
|
|
use IncidentCreateTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $pathMessage; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var FileNotificationType; |
|
26
|
|
|
*/ |
|
27
|
|
|
private $fileNType; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* set up file notification env. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setPathMessage(sys_get_temp_dir()); |
|
35
|
|
|
|
|
36
|
|
|
$this->setFileNType(new FileNotificationType($this->getPathMessage())); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* test email notify ok. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testNotify() |
|
43
|
|
|
{ |
|
44
|
|
|
$incident = $this->createIncidentMock(); |
|
45
|
|
|
|
|
46
|
|
|
$incident->expects($this->any())->method('getStatus')->willReturn(IncidentInterface::STATUS_OK + 1); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$subject = $this->createSubject('[email protected]', '* * * * *'); |
|
49
|
|
|
|
|
50
|
|
|
$this->getFileNType()->notify($subject, $incident); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$this->assertStringEqualsFile($this->getFileNType()->getSubjectNotifyFilePath($subject), $incident->getMessage()); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Test Message Not Writable throw Exception. |
|
57
|
|
|
* |
|
58
|
|
|
* @expectedException \TonicHealthCheck\Incident\Siren\NotificationType\FileNotificationTypeException |
|
59
|
|
|
* @expectedExceptionMessage Notification directory /test343/tes232 doesn't writable |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testPathMessageNotWritable() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->getFileNType()->setPathMessage('/test343/tes232'); |
|
64
|
|
|
} |
|
65
|
|
|
/** |
|
66
|
|
|
* @return FileNotificationType |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getFileNType() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->fileNType; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param FileNotificationType $fileNType |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function setFileNType(FileNotificationType $fileNType) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->fileNType = $fileNType; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getPathMessage() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->pathMessage; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param mixed $pathMessage |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function setPathMessage($pathMessage) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->pathMessage = $pathMessage; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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: