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 |
|
|
|
|
8
|
|
|
{ |
9
|
|
View Code Duplication |
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
|
|
|
$data = json_decode($response->getBody(true), true); |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testAlertHandlesEmptyData() |
19
|
|
|
{ |
20
|
|
|
$client = new Client(); |
21
|
|
|
$response = $client->request( |
22
|
|
|
'GET', |
23
|
|
|
'http://192.168.33.10/ps2alerts-api/public/v2/alerts/1', |
24
|
|
|
['http_errors' => false] |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
28
|
|
|
$this->assertTrue($response->hasHeader('Content-Type')); |
29
|
|
|
$data = json_decode($response->getBody(true), true); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->assertArrayHasKey('error', $data); |
32
|
|
|
$this->assertArrayHasKey('code', $data['error']); |
33
|
|
|
$this->assertArrayHasKey('http_code', $data['error']); |
34
|
|
|
$this->assertArrayHasKey('message', $data['error']); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function testAlertReturnsBody() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$client = new Client(); |
40
|
|
|
$response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000'); |
41
|
|
|
|
42
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
43
|
|
|
$data = json_decode($response->getBody(true), true); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testAlertReturnsJsonHeaders() |
47
|
|
|
{ |
48
|
|
|
$client = new Client(); |
49
|
|
|
$response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000'); |
50
|
|
|
|
51
|
|
|
$this->assertTrue($response->hasHeader('Content-Type')); |
52
|
|
|
$this->assertEquals('application/json', $response->getHeader('Content-Type')[0]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testAlertReturnsAnyData() |
56
|
|
|
{ |
57
|
|
|
$client = new Client(); |
58
|
|
|
$response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000'); |
59
|
|
|
|
60
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
61
|
|
|
$this->assertTrue($response->hasHeader('Content-Type')); |
62
|
|
|
$data = json_decode($response->getBody(true), true); |
|
|
|
|
63
|
|
|
$this->assertArrayHasKey('data', $data); |
64
|
|
|
$this->assertArrayHasKey('id', $data['data']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testAlertReturnsExpectedData() |
68
|
|
|
{ |
69
|
|
|
$client = new Client(); |
70
|
|
|
$response = $client->request('GET', 'http://192.168.33.10/ps2alerts-api/public/v2/alerts/10000'); |
71
|
|
|
|
72
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
73
|
|
|
$this->assertTrue($response->hasHeader('Content-Type')); |
74
|
|
|
$data = json_decode($response->getBody(true), true); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$this->assertArrayHasKey('data', $data); |
77
|
|
|
$this->assertArrayHasKey('id', $data['data']); |
78
|
|
|
$this->assertArrayHasKey('started', $data['data']); |
79
|
|
|
$this->assertArrayHasKey('ended', $data['data']); |
80
|
|
|
$this->assertArrayHasKey('server', $data['data']); |
81
|
|
|
$this->assertArrayHasKey('zone', $data['data']); |
82
|
|
|
$this->assertArrayHasKey('winner', $data['data']); |
83
|
|
|
$this->assertArrayHasKey('isDraw', $data['data']); |
84
|
|
|
$this->assertArrayHasKey('isDomination', $data['data']); |
85
|
|
|
$this->assertArrayHasKey('isValid', $data['data']); |
86
|
|
|
$this->assertArrayHasKey('inProgress', $data['data']); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.