Completed
Push — master ( 7860e0...d3b4dd )
by Matthew
02:30 queued 24s
created

AlertControllerTest::testAlertReturnsAnyData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
use GuzzleHttp\Client;
4
use GuzzleHttp\Psr7\Request;
5
use GuzzleHttp\Psr7\Response;
6
7
class AlertControllerTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    public function testAlertReturnsCorrectNonEmptyHttpCode()
10
    {
11
        $client = new Client();
12
        $response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000');
13
14
        $this->assertEquals(200, $response->getStatusCode());
15
    }
16
17
    public function testAlertHandlesEmptyData()
18
    {
19
        $client = new Client();
20
        $response = $client->request(
21
            'GET',
22
            'http://192.168.33.10/ps2alerts-api/public/v2/alerts/1',
23
            ['http_errors' => false]
24
        );
25
26
        $this->assertEquals(404, $response->getStatusCode());
27
        $this->assertTrue($response->hasHeader('Content-Type'));
28
        $data = json_decode($response->getBody(true), true);
0 ignored issues
show
Unused Code introduced by
The call to ResponseInterface::getBody() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
30
        $this->assertArrayHasKey('error', $data);
31
        $this->assertArrayHasKey('code', $data['error']);
32
        $this->assertArrayHasKey('http_code', $data['error']);
33
        $this->assertArrayHasKey('message', $data['error']);
34
    }
35
36
    public function testAlertReturnsBody()
37
    {
38
        $client = new Client();
39
        $response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000');
40
41
        $this->assertEquals(200, $response->getStatusCode());
42
        $data = json_decode($response->getBody(true), true);
0 ignored issues
show
Unused Code introduced by
The call to ResponseInterface::getBody() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
44
        $this->assertArrayHasKey('data', $data);
45
    }
46
47
    public function testAlertReturnsJsonHeaders()
48
    {
49
        $client = new Client();
50
        $response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000');
51
52
        $this->assertTrue($response->hasHeader('Content-Type'));
53
        $this->assertEquals('application/json', $response->getHeader('Content-Type')[0]);
54
    }
55
56
    public function testAlertReturnsAnyData()
57
    {
58
        $client = new Client();
59
        $response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000');
60
61
        $this->assertEquals(200, $response->getStatusCode());
62
        $this->assertTrue($response->hasHeader('Content-Type'));
63
        $data = json_decode($response->getBody(true), true);
0 ignored issues
show
Unused Code introduced by
The call to ResponseInterface::getBody() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
        $this->assertArrayHasKey('data', $data);
65
        $this->assertArrayHasKey('id', $data['data']);
66
    }
67
68
    public function testAlertReturnsExpectedData()
69
    {
70
        $client = new Client();
71
        $response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000');
72
73
        $this->assertEquals(200, $response->getStatusCode());
74
        $this->assertTrue($response->hasHeader('Content-Type'));
75
        $data = json_decode($response->getBody(true), true);
0 ignored issues
show
Unused Code introduced by
The call to ResponseInterface::getBody() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
76
77
        $this->assertArrayHasKey('data', $data);
78
        $this->assertArrayHasKey('id', $data['data']);
79
        $this->assertArrayHasKey('started', $data['data']);
80
        $this->assertArrayHasKey('ended', $data['data']);
81
        $this->assertArrayHasKey('server', $data['data']);
82
        $this->assertArrayHasKey('zone', $data['data']);
83
        $this->assertArrayHasKey('winner', $data['data']);
84
        $this->assertArrayHasKey('isDraw', $data['data']);
85
        $this->assertArrayHasKey('isDomination', $data['data']);
86
        $this->assertArrayHasKey('isValid', $data['data']);
87
        $this->assertArrayHasKey('inProgress', $data['data']);
88
    }
89
}
90