Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
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() |
||
90 | } |