TestIp.php 873 B

12345678910111213141516171819202122232425
  1. <?php
  2. require __DIR__.'/../vendor/autoload.php';
  3. use Zhuzhichao\IpLocationZh\Ip;
  4. use PHPUnit\Framework\TestCase;
  5. class TestIp extends TestCase
  6. {
  7. public function testIpLocation()
  8. {
  9. $this->assertEquals(['中国', '河南', '郑州', '', '410100'], Ip::find('171.12.10.156'));
  10. $this->assertEquals(['中国', '山东', '', '', '370000'], Ip::find('110.223.0.43'));
  11. $this->assertEquals(['本机地址', '本机地址', '', '', ''], Ip::find('127.0.0.1'));
  12. $this->assertEquals(['中国', '浙江', '杭州', '', '330100'], Ip::find('110.75.115.70'));
  13. }
  14. public function testIpLocations()
  15. {
  16. $locations = Ip::locations();
  17. $this->assertArrayHasKey('北京', $locations);
  18. $this->assertArrayHasKey('河北', $locations);
  19. $this->assertGreaterThan(0, count($locations['河北']['cities']));
  20. }
  21. }