Skip to content

Commit 9f862a4

Browse files
rvalitovmax-ipinfo
authored andcommitted
[fix] test call returns different data now, allow tests to pass with free token
1 parent b10968c commit 9f862a4

File tree

1 file changed

+70
-36
lines changed

1 file changed

+70
-36
lines changed

tests/IPinfoTest.php

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,39 @@ public function testLookup()
103103
$this->assertEquals($res->longitude, '-122.1175');
104104
$this->assertEquals($res->postal, '94043');
105105
$this->assertEquals($res->timezone, 'America/Los_Angeles');
106-
$this->assertEquals($res->asn['asn'], 'AS15169');
107-
$this->assertEquals($res->asn['name'], 'Google LLC');
108-
$this->assertEquals($res->asn['domain'], 'google.com');
109-
$this->assertEquals($res->asn['route'], '8.8.8.0/24');
110-
$this->assertEquals($res->asn['type'], 'hosting');
111-
$this->assertEquals($res->company['name'], 'Google LLC');
112-
$this->assertEquals($res->company['domain'], 'google.com');
113-
$this->assertEquals($res->company['type'], 'hosting');
114-
$this->assertEquals($res->privacy['vpn'], false);
115-
$this->assertEquals($res->privacy['proxy'], false);
116-
$this->assertEquals($res->privacy['tor'], false);
117-
$this->assertEquals($res->privacy['relay'], false);
118-
$this->assertEquals($res->privacy['hosting'], true);
119-
$this->assertEquals($res->privacy['service'], '');
120-
$this->assertEquals($res->abuse['address'], 'US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043');
121-
$this->assertEquals($res->abuse['country'], 'US');
122-
$this->assertEquals($res->abuse['email'], '[email protected]');
123-
$this->assertEquals($res->abuse['name'], 'Abuse');
124-
$this->assertEquals($res->abuse['network'], '8.8.8.0/24');
125-
$this->assertEquals($res->abuse['phone'], '+1-650-253-0000');
126-
$this->assertEquals($res->domains['ip'], '8.8.8.8');
106+
if ($res->asn !== null) {
107+
$this->assertEquals($res->asn['asn'], 'AS15169');
108+
$this->assertEquals($res->asn['name'], 'Google LLC');
109+
$this->assertEquals($res->asn['domain'], 'google.com');
110+
$this->assertEquals($res->asn['route'], '8.8.8.0/24');
111+
$this->assertEquals($res->asn['type'], 'hosting');
112+
}
113+
if ($res->company !== null) {
114+
$this->assertEquals($res->company['name'], 'Google LLC');
115+
$this->assertEquals($res->company['domain'], 'google.com');
116+
$this->assertEquals($res->company['type'], 'hosting');
117+
}
118+
if ($res->privacy !== null) {
119+
$this->assertEquals($res->privacy['vpn'], false);
120+
$this->assertEquals($res->privacy['proxy'], false);
121+
$this->assertEquals($res->privacy['tor'], false);
122+
$this->assertEquals($res->privacy['relay'], false);
123+
if ($res->privacy['hosting'] !== null) {
124+
$this->assertEquals($res->privacy['hosting'], true);
125+
}
126+
$this->assertEquals($res->privacy['service'], '');
127+
}
128+
if ($res->abuse !== null) {
129+
$this->assertEquals($res->abuse['address'], 'US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043');
130+
$this->assertEquals($res->abuse['country'], 'US');
131+
$this->assertEquals($res->abuse['email'], '[email protected]');
132+
$this->assertEquals($res->abuse['name'], 'Abuse');
133+
$this->assertEquals($res->abuse['network'], '8.8.8.0/24');
134+
$this->assertEquals($res->abuse['phone'], '+1-650-253-0000');
135+
}
136+
if ($res->domains !== null) {
137+
$this->assertEquals($res->domains['ip'], '8.8.8.8');
138+
}
127139
}
128140
}
129141

@@ -191,23 +203,45 @@ public function testGetBatchDetails()
191203
$this->assertArrayHasKey('9.9.9.9', $res);
192204
$this->assertArrayHasKey('10.10.10.10', $res);
193205
$this->assertEquals($res['8.8.8.8/hostname'], 'dns.google');
206+
$ipV4 = $res['4.4.4.4'];
207+
$this->assertEquals($ipV4['ip'], '4.4.4.4');
208+
$this->assertEquals($ipV4['city'], 'Monroe');
209+
$this->assertEquals($ipV4['region'], 'Louisiana');
210+
$this->assertEquals($ipV4['country'], 'US');
211+
$this->assertEquals($ipV4['loc'], '32.5530,-92.0422');
212+
$this->assertEquals($ipV4['postal'], '71203');
213+
$this->assertEquals($ipV4['timezone'], 'America/Chicago');
214+
$this->assertEquals($ipV4['org'], 'AS3356 Level 3 Parent, LLC');
215+
}
216+
}
194217

195-
$this->assertEquals($res['AS123'], [
196-
'asn' => "AS123",
197-
'name' => "Air Force Systems Networking",
198-
'country' => "US",
199-
'allocated' => "1987-08-24",
200-
'registry' => "arin",
201-
'domain' => "af.mil",
202-
'num_ips' => 0,
203-
'type' => "inactive",
204-
'prefixes' => [],
205-
'prefixes6' => [],
206-
'peers' => null,
207-
'upstreams' => null,
208-
'downstreams' => null
209-
]);
218+
public function getNetworkDetails()
219+
{
220+
$tok = getenv('IPINFO_TOKEN');
221+
if (!$tok) {
222+
$this->markTestSkipped('IPINFO_TOKEN env var required');
210223
}
224+
225+
$h = new IPinfo($tok);
226+
$res = $h->getDetails('AS123');
227+
228+
if ($res['error'] === "Token does not have access to this API") {
229+
$this->markTestSkipped('Token does not have access to this API');
230+
}
231+
232+
$this->assertEquals($res['asn'], 'AS123');
233+
$this->assertEquals($res['name'], 'Air Force Systems Networking');
234+
$this->assertEquals($res['country'], 'US');
235+
$this->assertEquals($res['allocated'], '1987-08-24');
236+
$this->assertEquals($res['registry'], 'arin');
237+
$this->assertEquals($res['domain'], 'af.mil');
238+
$this->assertEquals($res['num_ips'], 0);
239+
$this->assertEquals($res['type'], 'inactive');
240+
$this->assertEquals($res['prefixes'], []);
241+
$this->assertEquals($res['prefixes6'], []);
242+
$this->assertEquals($res['peers'], null);
243+
$this->assertEquals($res['upstreams'], null);
244+
$this->assertEquals($res['downstreams'], null);
211245
}
212246

213247
public function testBogonLocal4()

0 commit comments

Comments
 (0)