mirror of
https://github.com/chinayin/ip2region-core-php.git
synced 2025-12-04 04:42:14 +08:00
fix TestCase.php
This commit is contained in:
parent
1cb26e6da0
commit
4e665979e5
@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
namespace ip2region\Tests;
|
namespace ip2region\Tests;
|
||||||
|
|
||||||
use ip2region\XdbSearcher;
|
|
||||||
|
|
||||||
class TestCase extends \PHPUnit\Framework\TestCase
|
class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
public static function now()
|
public static function now()
|
||||||
@ -24,24 +22,4 @@ class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
return microtime(true) * 1000;
|
return microtime(true) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test()
|
|
||||||
{
|
|
||||||
$ip = '1.2.3.4';
|
|
||||||
$xdb = './ip2region.xdb';
|
|
||||||
try {
|
|
||||||
// 1、加载整个 xdb 到内存。
|
|
||||||
$cBuff = XdbSearcher::loadContentFromFile($xdb);
|
|
||||||
if (null === $cBuff) {
|
|
||||||
throw new \RuntimeException("failed to load content buffer from '$xdb'");
|
|
||||||
}
|
|
||||||
// 2、使用全局的 cBuff 创建带完全基于内存的查询对象。
|
|
||||||
$searcher = XdbSearcher::newWithBuffer($cBuff);
|
|
||||||
// 3、查询
|
|
||||||
$region = $searcher->search($ip);
|
|
||||||
var_dump($region);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
var_dump($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user