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'))); }
/** * */ protected function division() { DatabaseQuery::initDivision(function ($code, $n) { static $total = 0; switch ($code) { case 0: $this->stdout("generate divisions table:\n", Console::FG_GREEN); if (empty($this->controller->noProgress)) { Console::startProgress(0, $n); } $total = $n; break; case 1: if (empty($this->controller->noProgress)) { Console::updateProgress($n, $total); } break; case 2: if (empty($this->controller->noProgress)) { Console::updateProgress($total, $total); Console::endProgress(); } $this->stdout(" completed!\n", Console::FG_GREEN); break; } }, true); }
/** * @param OutputInterface $output * @param bool $noProgress */ protected function division(OutputInterface $output, $noProgress) { DatabaseQuery::initDivision(function ($code, $n) use($output, $noProgress) { switch ($code) { case 0: $output->writeln("<info>generate divisions table:</info>"); if (!$noProgress) { $this->progress = new ProgressBar($output, $n); $this->progress->start(); } break; case 1: if (!$noProgress) { $this->progress->setProgress($n); } break; case 2: if (!$noProgress) { $this->progress->finish(); } $output->writeln('<info> completed!</info>'); break; } }, true); }