1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019 - present |
4
|
|
|
* updown - EventTest.phpthor: Roberto Belotti - [email protected] |
5
|
|
|
* web : robertobelotti.com, github.com/biscolab |
6
|
|
|
* Initial version created on: 18/2/2019 |
7
|
|
|
* MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tests\Unit; |
11
|
|
|
|
12
|
|
|
use Biscolab\UpDown\Fields\CheckFields; |
13
|
|
|
use Biscolab\UpDown\Fields\DownTimeFields; |
14
|
|
|
use Biscolab\UpDown\Fields\EventFields; |
15
|
|
|
use Biscolab\UpDown\Objects\Check; |
16
|
|
|
use Biscolab\UpDown\Objects\Event; |
17
|
|
|
use Biscolab\UpDown\Tests\TestCase; |
18
|
|
|
use Biscolab\UpDown\Types\DownTime; |
19
|
|
|
|
20
|
|
|
class EventTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
protected $web_hook; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
*/ |
28
|
1 |
|
public function testSetWebHook() |
29
|
|
|
{ |
30
|
|
|
|
31
|
1 |
|
$this->assertInstanceOf(Check::class, $this->web_hook->{EventFields::CHECK}); |
32
|
1 |
|
$this->assertInstanceOf(DownTime::class, $this->web_hook->{EventFields::DOWNTIME}); |
33
|
|
|
|
34
|
1 |
|
$this->assertEquals("500", $this->web_hook->{EventFields::DOWNTIME}->{DownTimeFields::ERROR}); |
35
|
1 |
|
$this->assertEquals("2016", date('Y', $this->web_hook->{EventFields::DOWNTIME}->{DownTimeFields::STARTED_AT})); |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
1 |
|
public function testWebHookGetEvent() |
42
|
|
|
{ |
43
|
|
|
|
44
|
1 |
|
$this->assertEquals("check.up", $this->web_hook->{EventFields::EVENT}); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @test |
49
|
|
|
*/ |
50
|
1 |
|
public function testDateTimeFields() |
51
|
|
|
{ |
52
|
|
|
|
53
|
1 |
|
$this->assertEquals("2016", date('Y', $this->web_hook->{EventFields::CHECK}->{CheckFields::LAST_CHECK_AT})); |
54
|
|
|
|
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Setup the test environment. |
59
|
|
|
*/ |
60
|
3 |
|
protected function setUp() |
61
|
|
|
{ |
62
|
|
|
|
63
|
3 |
|
parent::setUp(); // TODO: Change the autogenerated stub |
64
|
|
|
|
65
|
|
|
$data = [ |
66
|
3 |
|
"event" => "check.up", |
67
|
|
|
"check" => [ |
68
|
|
|
"token" => "ngg8", |
69
|
|
|
"url" => "https://updown.io", |
70
|
|
|
"alias" => "", |
71
|
|
|
"last_status" => 200, |
72
|
|
|
"uptime" => 99.954, |
73
|
|
|
"down" => false, |
74
|
|
|
"down_since" => null, |
75
|
|
|
"error" => null, |
76
|
|
|
"period" => 30, |
77
|
|
|
"apdex_t" => 0.25, |
78
|
|
|
"string_match" => "", |
79
|
|
|
"enabled" => true, |
80
|
|
|
"published" => true, |
81
|
|
|
"disabled_locations" => [], |
82
|
|
|
"last_check_at" => "2016-02-07T13:16:07Z", |
83
|
|
|
"next_check_at" => "2016-02-07T13:16:37Z", |
84
|
|
|
"mute_until" => null, |
85
|
|
|
"favicon_url" => "https://updown.io/favicon.png", |
86
|
|
|
"custom_headers" => [] |
87
|
|
|
], |
88
|
|
|
"downtime" => [ |
89
|
|
|
"error" => "500", |
90
|
|
|
"started_at" => "2016-02-07T13:11:43Z", |
91
|
|
|
"ended_at" => "2016-02-07T13:16:07Z", |
92
|
|
|
"duration" => 265 |
93
|
|
|
] |
94
|
|
|
]; |
95
|
|
|
|
96
|
3 |
|
$this->web_hook = new Event($data); |
97
|
|
|
} |
98
|
|
|
} |