Exemplo n.º 1
0
 /**
  *
  */
 public function testSetProviders()
 {
     $dummy = new DummyQuery();
     $this->assertEmpty($dummy->getProviders());
     $dummy->setProviders([new FreeipipQuery()]);
     $this->assertCount(1, $dummy->getProviders());
 }
Exemplo n.º 2
0
 /**
  * @throws \Exception
  */
 public function testInit()
 {
     $filename = __DIR__ . '/test.dat';
     $dummy = new DummyQuery();
     $dummy->init();
     $export = new Export($filename);
     $export->setProviders([$dummy]);
     $export->init();
     $query = new Query($filename);
     $this->assertEquals("4\t4\t\t", $query->find(ip2long('0.0.0.0')));
     $this->assertEquals("4\t4\t\t", $query->find(ip2long('0.255.255.254')));
     $this->assertEquals("4\t4\t\t", $query->find(ip2long('0.255.255.255')));
     $this->assertEquals("0\t0\t\t", $query->find(ip2long('3.4.5.6')));
     $this->assertEquals("2\t2\t\t", $query->find(ip2long('127.0.0.1')));
     $this->assertEquals("3\t3\t\t", $query->find(ip2long('192.168.10.1')));
     $this->assertEquals("5\t5\t\t", $query->find(ip2long('169.254.1.1')));
     $this->assertStringStartsWith('ipv4.larryli.cn', $query->find(ip2long('255.255.255.254')));
     $query->clean();
 }
Exemplo n.º 3
0
 public function testTranslateId()
 {
     $query0 = new DummyQuery();
     $query0->init();
     $query = new DummyPlusDatabaseQuery(new DummyDatabase());
     DatabaseQuery::initDivision();
     $this->assertFalse($query->exists());
     $query->setProviders([$query0]);
     $query->init();
     $this->assertEquals(5, $query->findId(ip2long('0.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('1.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('2.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('3.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('4.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('5.0.0.0')));
     $this->assertEquals(1, $query->findId(ip2long('6.0.0.0')));
     $this->assertEquals(4, $query->findId(ip2long('10.0.0.0')));
     $this->assertEquals(3, $query->findId(ip2long('127.0.0.1')));
     $this->assertEquals(4, $query->findId(ip2long('127.0.0.2')));
 }