Completed
Push — master ( 2132b9...0efe7a )
by Roberto
02:52
created

WebHookTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 37
dl 0
loc 77
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

4 Methods

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