1
|
|
|
<?php |
2
|
|
|
namespace Azine\MailgunWebhooksBundle\Tests\Services\HetrixtoolsService; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService; |
6
|
|
|
use Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\HetrixtoolsServiceResponse; |
7
|
|
|
|
8
|
|
|
class AzineMailgunHetrixtoolsServiceTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
private $responseJson = '{ |
11
|
|
|
"status": "SUCCESS", |
12
|
|
|
"api_calls_left": 1976, |
13
|
|
|
"blacklist_check_credits_left": 81, |
14
|
|
|
"blacklisted_count": 3, |
15
|
|
|
"blacklisted_on": [ |
16
|
|
|
{ |
17
|
|
|
"rbl": "example1.com", |
18
|
|
|
"delist": "https://1.example.com/ip/198.51.100.42" |
19
|
|
|
}, |
20
|
|
|
{ |
21
|
|
|
"rbl": "example2.org", |
22
|
|
|
"delist": "https://2.example.com/query/ip/198.51.100.42" |
23
|
|
|
}, |
24
|
|
|
{ |
25
|
|
|
"rbl": "example3.org", |
26
|
|
|
"delist": "https://3.example.com/query/ip/198.51.100.42" |
27
|
|
|
} |
28
|
|
|
], |
29
|
|
|
"links": { |
30
|
|
|
"report_link": "https://3.example.com/report/blacklist/token/", |
31
|
|
|
"whitelabel_report_link": "", |
32
|
|
|
"api_report_link": "https://api.example.com/v1/token/report/198.51.100.42/", |
33
|
|
|
"api_blacklist_check_link": "https://api.example.com/v2/token/blacklist-check/ipv4/198.51.100.42/" |
34
|
|
|
} |
35
|
|
|
}'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @expectedException \InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function testIfApiKeyisNotSet() |
41
|
|
|
{ |
42
|
|
|
$apiKey = ''; |
43
|
|
|
$url = 'blacklistIpCheckUr'; |
44
|
|
|
|
45
|
|
|
$ip = '198.51.100.42'; |
46
|
|
|
$service = new AzineMailgunHetrixtoolsService($apiKey, $url); |
47
|
|
|
$service->checkIpAddressInBlacklist($ip); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @expectedException \InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testIfEmptyIpisGiven() |
54
|
|
|
{ |
55
|
|
|
$apiKey = 'testApiKey'; |
56
|
|
|
$url = 'blacklistIpCheckUr'; |
57
|
|
|
$ip = ''; |
58
|
|
|
|
59
|
|
|
$service = new AzineMailgunHetrixtoolsService($apiKey, $url); |
60
|
|
|
$service->checkIpAddressInBlacklist($ip); |
61
|
|
|
} |
62
|
|
|
/** |
63
|
|
|
* @expectedException \InvalidArgumentException |
64
|
|
|
*/ |
65
|
|
|
public function testIfInvalidIpisGiven() |
66
|
|
|
{ |
67
|
|
|
$apiKey = 'testApiKey'; |
68
|
|
|
$url = 'blacklistIpCheckUr'; |
69
|
|
|
$ip = 'invalidIpAddress'; |
70
|
|
|
|
71
|
|
|
$service = new AzineMailgunHetrixtoolsService($apiKey, $url); |
72
|
|
|
$service->checkIpAddressInBlacklist($ip); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testSuccessReponse() |
76
|
|
|
{ |
77
|
|
|
$apiKey = 'test'; |
78
|
|
|
$url = 'https://api.example.com/v2/testkey/blacklist-check/ipv4/198.51.100.42/'; |
79
|
|
|
|
80
|
|
|
$hetrixtoolsService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService") |
81
|
|
|
->setConstructorArgs([$apiKey, $url]) |
82
|
|
|
->setMethods(array('executeCheck'))->getMock(); |
83
|
|
|
$hetrixtoolsService->expects($this->once())->method("executeCheck")->will($this->returnValue($this->responseJson)); |
84
|
|
|
|
85
|
|
|
/** @var AzineMailgunHetrixtoolsService $hetrixtoolsService */ |
86
|
|
|
$response = $hetrixtoolsService->checkIpAddressInBlacklist('198.51.100.42'); |
87
|
|
|
|
88
|
|
|
$this->assertInstanceOf(HetrixtoolsServiceResponse::class, $response); |
89
|
|
|
} |
90
|
|
|
} |