|
1
|
|
|
<?php |
|
2
|
|
|
namespace Azine\MailgunWebhooksBundle\Tests\Services\HetrixtoolsService; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\HetrixtoolsServiceResponse; |
|
6
|
|
|
|
|
7
|
|
|
class HetrixtoolsServiceResponseTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testHetrixtoolsServiceResponse() |
|
10
|
|
|
{ |
|
11
|
|
|
$responseJson = '{ |
|
12
|
|
|
"status": "SUCCESS", |
|
13
|
|
|
"api_calls_left": 1976, |
|
14
|
|
|
"blacklist_check_credits_left": 81, |
|
15
|
|
|
"blacklisted_count": 3, |
|
16
|
|
|
"blacklisted_on": [ |
|
17
|
|
|
{ |
|
18
|
|
|
"rbl": "example1.com", |
|
19
|
|
|
"delist": "https://1.example.com/ip/198.51.100.42" |
|
20
|
|
|
}, |
|
21
|
|
|
{ |
|
22
|
|
|
"rbl": "example2.org", |
|
23
|
|
|
"delist": "https://2.example.com/query/ip/198.51.100.42" |
|
24
|
|
|
}, |
|
25
|
|
|
{ |
|
26
|
|
|
"rbl": "example3.org", |
|
27
|
|
|
"delist": "https://3.example.com/query/ip/198.51.100.42" |
|
28
|
|
|
} |
|
29
|
|
|
], |
|
30
|
|
|
"links": { |
|
31
|
|
|
"report_link": "https://3.example.com/report/blacklist/token/", |
|
32
|
|
|
"whitelabel_report_link": "", |
|
33
|
|
|
"api_report_link": "https://api.example.com/v1/token/report/198.51.100.42/", |
|
34
|
|
|
"api_blacklist_check_link": "https://api.example.com/v2/token/blacklist-check/ipv4/198.51.100.42/" |
|
35
|
|
|
} |
|
36
|
|
|
}'; |
|
37
|
|
|
|
|
38
|
|
|
$response = HetrixtoolsServiceResponse::fromJson($responseJson); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertInstanceOf(HetrixtoolsServiceResponse::class, $response); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @expectedException \InvalidArgumentException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testHetrixtoolsServiceResponseEmptyJson() |
|
47
|
|
|
{ |
|
48
|
|
|
//Test with empty string |
|
49
|
|
|
$responseJson = ''; |
|
50
|
|
|
HetrixtoolsServiceResponse::fromJson($responseJson); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @expectedException \InvalidArgumentException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testHetrixtoolsServiceResponseWrongJson() |
|
57
|
|
|
{ |
|
58
|
|
|
//Test with invalid Json |
|
59
|
|
|
$responseJson = 'invalidJson'; |
|
60
|
|
|
HetrixtoolsServiceResponse::fromJson($responseJson); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @expectedException \InvalidArgumentException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testHetrixtoolsServiceResponseNullJson() |
|
67
|
|
|
{ |
|
68
|
|
|
//Test with invalid Json |
|
69
|
|
|
HetrixtoolsServiceResponse::fromJson(null); |
|
70
|
|
|
} |
|
71
|
|
|
} |