fix TestCase.php

This commit is contained in:
lei.tian 2022-06-30 19:05:11 +08:00
parent 1cb26e6da0
commit 4e665979e5

View File

@ -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());
}
}
} }