Skip to content

Commit 4fd65dc

Browse files
Added PHPUnit test cases
1 parent e7fe904 commit 4fd65dc

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"email": "support@ip2location.com",
1111
"homepage": "https://www.ip2location.com"
1212
}
13-
]
13+
],
14+
"require-dev": {
15+
"phpunit/phpunit": "^9"
16+
}
1417
}

libraries/ip2proxy/IP2PROXY.BIN

1 MB
Binary file not shown.

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit bootstrap="tests/bootstrap.php" colors="true">
2+
<testsuites>
3+
<testsuite name="IP2Proxy CodeIgniter Testcase">
4+
<directory suffix="Test.php">./tests/</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

tests/FunctionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
require_once './libraries/IP2Proxy_lib.php';
8+
9+
class FunctionTest extends TestCase
10+
{
11+
public function testGetDb() {
12+
define('IP2PROXY_DATABASE', '.\libraries\ip2proxy\IP2PROXY.BIN');
13+
$ipx = new \App\Libraries\IP2Proxy_lib();
14+
$countryCode = $ipx->getCountryShort('1.0.241.135');
15+
16+
$this->assertEquals(
17+
'TH',
18+
$countryCode,
19+
);
20+
}
21+
22+
public function testGetWebService() {
23+
$ipx = new \App\Libraries\IP2Proxy_lib();
24+
$record = $ipx->getWebService('1.0.241.135');
25+
26+
$this->assertEquals(
27+
'TH',
28+
$record['countryCode'],
29+
);
30+
}
31+
}

tests/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
if (!$loader = @include './vendor/autoload.php') {
6+
die('Project dependencies missing');
7+
}
8+
9+
$loader->add('IP2Proxy\Test', __DIR__);

0 commit comments

Comments
 (0)