Skip to content

Commit 092a2e5

Browse files
committed
Added additional test cases.
1 parent 9839f14 commit 092a2e5

File tree

2 files changed

+104
-14
lines changed

2 files changed

+104
-14
lines changed

src/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Database
1212
*
1313
* @var string
1414
*/
15-
private const VERSION = '4.0.0';
15+
private const VERSION = '4.0.1';
1616

1717
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1818
// Error field constants ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -118,7 +118,7 @@ class Database
118118
*
119119
* @var int
120120
*/
121-
private const _AS = 11;
121+
public const _AS = 11;
122122

123123
/**
124124
* Last seen.

tests/DatabaseTest.php

Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public function testIpv4CountryCode()
3232

3333
$records = $db->lookup('1.0.0.8', \IP2Proxy\Database::ALL);
3434

35-
$this->assertEquals(
36-
'US',
37-
$records['countryCode'],
38-
);
35+
$this->assertEquals('US', $records['countryCode']);
3936
}
4037

4138
public function testIpv4CountryName()
@@ -50,16 +47,91 @@ public function testIpv4CountryName()
5047
);
5148
}
5249

50+
public function testLookupCountryCode() {
51+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
52+
53+
$this->assertEquals('US', $db->lookup('1.0.0.8', \IP2Proxy\Database::COUNTRY_CODE));
54+
}
55+
56+
public function testLookupCountryName() {
57+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
58+
59+
$this->assertEquals('United States of America', $db->lookup('1.0.0.8', \IP2Proxy\Database::COUNTRY_NAME));
60+
}
61+
62+
public function testLookupRegionName() {
63+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
64+
65+
$this->assertEquals('California', $db->lookup('1.0.0.8', \IP2Proxy\Database::REGION_NAME));
66+
}
67+
68+
public function testLookupCityName() {
69+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
70+
71+
$this->assertEquals('Los Angeles', $db->lookup('1.0.0.8', \IP2Proxy\Database::CITY_NAME));
72+
}
73+
74+
public function testLookupIsp() {
75+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
76+
77+
$this->assertEquals('APNIC and CloudFlare DNS Resolver Project', $db->lookup('1.0.0.8', \IP2Proxy\Database::ISP));
78+
}
79+
80+
public function testLookupIsProxy() {
81+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
82+
83+
$this->assertEquals(2, (string) $db->lookup('1.0.0.8', \IP2Proxy\Database::IS_PROXY));
84+
}
85+
86+
public function testLookupProxyType() {
87+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
88+
89+
$this->assertEquals('DCH', $db->lookup('1.0.0.8', \IP2Proxy\Database::PROXY_TYPE));
90+
}
91+
92+
public function testLookupDomain() {
93+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
94+
95+
$this->assertEquals('cloudflare.com', $db->lookup('1.0.0.8', \IP2Proxy\Database::DOMAIN));
96+
}
97+
98+
public function testLookupUsageType() {
99+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
100+
101+
$this->assertEquals('CDN', $db->lookup('1.0.0.8', \IP2Proxy\Database::USAGE_TYPE));
102+
}
103+
104+
public function testLookupAsn() {
105+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
106+
107+
$this->assertEquals('13335', $db->lookup('1.0.0.8', \IP2Proxy\Database::ASN));
108+
}
109+
110+
public function testLookupAs() {
111+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
112+
113+
$this->assertEquals('CLOUDFLARENET', $db->lookup('1.0.0.8', \IP2Proxy\Database::_AS));
114+
}
115+
116+
public function testLookupLastSeen() {
117+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
118+
119+
$this->assertEquals('22', $db->lookup('1.0.0.8', \IP2Proxy\Database::LAST_SEEN));
120+
}
121+
122+
public function testLookupThreat() {
123+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
124+
125+
$this->assertEquals('-', $db->lookup('1.0.0.8', \IP2Proxy\Database::THREAT));
126+
}
127+
53128
public function testIpv6CountryCode()
54129
{
55130
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
56131

57132
$records = $db->lookup('2c0f:ffa0::4', \IP2Proxy\Database::ALL);
58133

59-
$this->assertEquals(
60-
'UG',
61-
$records['countryCode'],
62-
);
134+
$this->assertEquals('UG', $records['countryCode']);
63135
}
64136

65137
public function testIpv6CountryName()
@@ -68,9 +140,27 @@ public function testIpv6CountryName()
68140

69141
$records = $db->lookup('2c0f:ffa0::4', \IP2Proxy\Database::ALL);
70142

71-
$this->assertEquals(
72-
'Uganda',
73-
$records['countryName'],
74-
);
143+
$this->assertEquals('Uganda', $records['countryName']);
144+
}
145+
146+
public function testPackageVersion()
147+
{
148+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
149+
150+
$this->assertMatchesRegularExpression('/^[0-9]+$/', (string) $db->getPackageVersion());
151+
}
152+
153+
public function testModuleVersion()
154+
{
155+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
156+
157+
$this->assertMatchesRegularExpression('/^[0-9]+\.[0-9]+\.[0-9]+$/', (string) $db->getModuleVersion());
158+
}
159+
160+
public function testDatabaseVersion()
161+
{
162+
$db = new \IP2Proxy\Database('./data/PX10.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
163+
164+
$this->assertMatchesRegularExpression('/^[0-9]+\.[0-9]+\.[0-9]+$/', (string) $db->getDatabaseVersion());
75165
}
76166
}

0 commit comments

Comments
 (0)