/**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessageRegExp %s must be an instance of \GeoIp2\Database\Reader.
  */
 public function testCreateWithWrongReaderClass()
 {
     $dbCode = 'some_db_code';
     $dbPath = 'some_absolute_db_path';
     $data = ['filename' => $dbPath, 'locales' => ['en']];
     $this->database->expects($this->once())->method('isDbAvailable')->with($dbCode)->willReturn(true);
     $this->database->expects($this->once())->method('getDbPath')->with($dbCode, true)->willReturn($dbPath);
     $reader = $this->getMockBuilder('GeoIp2\\Database\\WrongReader')->disableOriginalConstructor()->getMock();
     $this->objectManager->expects($this->once())->method('create')->with($this->instanceName, $data)->willReturn($reader);
     $this->readerFactory->create($dbCode);
 }
 /**
  * @param string $dbCode
  * @param array $locales
  * @return \GeoIp2\Database\Reader
  * @throws LocalizedException
  */
 public function create($dbCode, array $locales = ['en'])
 {
     if (!$this->database->isDbAvailable($dbCode)) {
         throw new LocalizedException(__('GeoIp2 database with "%1" code is not declared.', $dbCode));
     }
     $reader = $this->objectManager->create($this->instanceName, ['filename' => $this->database->getDbPath($dbCode, true), 'locales' => $locales]);
     if (!$reader instanceof \GeoIp2\Database\Reader) {
         throw new \InvalidArgumentException(get_class($reader) . ' must be an instance of \\GeoIp2\\Database\\Reader.');
     }
     return $reader;
 }
Example #3
0
 /**
  * @param string $dbCode
  * @throws LocalizedException
  */
 protected function unpackDb($dbCode)
 {
     $this->archive->unpack($this->directory->getAbsolutePath($this->getDbArchiveFilePath($dbCode)), $this->directory->getAbsolutePath($this->database->getDbPath($dbCode)));
     if (!$this->directory->isExist($this->database->getDbPath($dbCode))) {
         throw new LocalizedException(__('Cannot unpack db file.'));
     }
 }
 /**
  * @param string $dbCode
  * @param array $stat
  * @param string|null $stateCode
  * @param string|array|bool $result
  * @dataProvider getDbFileStatDataProvider
  */
 public function testGetDbFileStat($dbCode, $stat, $stateCode, $result)
 {
     $this->configureDirectoryIsFileIsReadableMethods($dbCode, true, true);
     $dbPath = $this->getDbPathNonAbsolute($dbCode);
     if ($dbPath) {
         $this->directory->expects($this->once())->method('stat')->with($dbPath)->willReturn($stat);
     }
     $this->assertEquals($result, $this->database->getDbFileStat($dbCode, $stateCode));
 }
Example #5
0
 /**
  * @param string $dbCode
  * @return \DateTime
  */
 protected function getDbDateTime($dbCode)
 {
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($this->database->getDbFileStat($dbCode, 'mtime'));
     return $dateTime;
 }
Example #6
0
 /**
  * @param string $dbCode
  * @param string $dbPath
  * @param string $dbArchPath
  * @param string $dbUrl
  * @param string $dbContent
  */
 protected function configureDownload($dbCode, $dbPath, $dbArchPath, $dbUrl, $dbContent)
 {
     $this->updater->expects($this->once())->method('loadDbContent')->with($dbUrl)->willReturn($dbContent);
     $this->database->expects($this->atLeastOnce())->method('getDbPath')->with($dbCode)->willReturn($dbPath);
     $this->directory->expects($this->atLeastOnce())->method('writeFile')->with($dbArchPath, $dbContent);
 }