Skip to content

Commit f038e11

Browse files
committed
Added PHPUnit test cases
1 parent a825ebb commit f038e11

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

composer.json

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

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="IP2Location CodeIgniter Testcase">
4+
<directory suffix="Test.php">./tests/</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

tests/FunctionTest.php

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

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('IP2Location\Test', __DIR__);

0 commit comments

Comments
 (0)