2013-07-15 22:52:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace GeoIp2\Test\WebService;
|
|
|
|
|
|
|
|
use GeoIp2\Database\Reader;
|
|
|
|
|
|
|
|
class ReaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testDefaultLanguage()
|
|
|
|
{
|
2013-07-15 23:10:05 +00:00
|
|
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
2013-07-16 16:44:30 +00:00
|
|
|
$this->checkAllMethods(
|
|
|
|
function ($method) use (&$reader) {
|
|
|
|
$record = $reader->$method('81.2.69.160');
|
|
|
|
$this->assertEquals('United Kingdom', $record->country->name);
|
|
|
|
}
|
|
|
|
);
|
2013-07-15 22:52:07 +00:00
|
|
|
$reader->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLanguageList()
|
|
|
|
{
|
|
|
|
$reader = new Reader(
|
2013-07-15 23:10:05 +00:00
|
|
|
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
|
2013-07-15 22:52:07 +00:00
|
|
|
array('xx', 'ru', 'pt-BR', 'es', 'en')
|
|
|
|
);
|
2013-07-16 16:44:30 +00:00
|
|
|
$this->checkAllMethods(
|
|
|
|
function ($method) use (&$reader) {
|
|
|
|
$record = $reader->$method('81.2.69.160');
|
|
|
|
$this->assertEquals('Великобритания', $record->country->name);
|
|
|
|
}
|
|
|
|
);
|
2013-07-15 22:52:07 +00:00
|
|
|
$reader->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHasIpAddress()
|
|
|
|
{
|
2013-07-15 23:10:05 +00:00
|
|
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
2013-07-16 16:44:30 +00:00
|
|
|
$this->checkAllMethods(
|
|
|
|
function ($method) use (&$reader) {
|
|
|
|
$record = $reader->$method('81.2.69.160');
|
|
|
|
$this->assertEquals('81.2.69.160', $record->traits->ipAddress);
|
|
|
|
}
|
|
|
|
);
|
2013-07-15 22:52:07 +00:00
|
|
|
$reader->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException GeoIp2\Exception\AddressNotFoundException
|
|
|
|
* @expectedExceptionMessage The address 10.10.10.10 is not in the database.
|
|
|
|
*/
|
|
|
|
public function testUnknownAddress()
|
|
|
|
{
|
2013-07-15 23:10:05 +00:00
|
|
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
2013-07-15 22:52:07 +00:00
|
|
|
$reader->city('10.10.10.10');
|
|
|
|
$reader->close();
|
|
|
|
}
|
2013-07-15 23:05:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
* @expectedExceptionMessage invalid is not a valid IP address
|
|
|
|
*/
|
|
|
|
public function testInvalidAddress()
|
|
|
|
{
|
2013-07-15 23:10:05 +00:00
|
|
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
2013-07-15 23:05:08 +00:00
|
|
|
$reader->city('invalid');
|
|
|
|
$reader->close();
|
|
|
|
}
|
2013-07-16 16:44:30 +00:00
|
|
|
|
|
|
|
public function checkAllMethods($testCb)
|
|
|
|
{
|
|
|
|
foreach (array('city', 'cityIspOrg', 'country', 'omni') as $method) {
|
|
|
|
call_user_func_array($testCb, array($method));
|
|
|
|
}
|
|
|
|
}
|
2013-07-15 22:52:07 +00:00
|
|
|
}
|