Author: Thomas Müller (t_mueller_stolzenhain@yahoo.de)
Ejemplo n.º 1
0
 /**
  * @expectedException \BrowscapPHP\Helper\Exception
  * @expectedExceptionMessage could not load the new version
  */
 public function testGetRemoteVersionException()
 {
     $loader = $this->getMock('\\FileLoader\\Loader', array('load', 'setRemoteDataUrl', 'setRemoteVerUrl', 'setTimeout'), array(), '', false);
     $loader->expects(self::once())->method('load')->will(self::throwException(new LoaderException()));
     $loader->expects(self::once())->method('setRemoteDataUrl')->will(self::returnSelf());
     $loader->expects(self::once())->method('setRemoteVerUrl')->will(self::returnSelf());
     $loader->expects(self::once())->method('setTimeout')->will(self::returnSelf());
     $this->object->setLoader($loader);
     $logger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false);
     $this->object->setLogger($logger);
     $this->object->getRemoteVersion();
 }
Ejemplo n.º 2
0
 /**
  * reads and parses an ini file and writes the results into the cache
  *
  * @param  string $iniFile
  *
  * @throws \BrowscapPHP\Exception
  */
 public function convertFile($iniFile)
 {
     $loader = new IniLoader();
     try {
         $loader->setLocalFile($iniFile);
     } catch (Helper\Exception $e) {
         throw new Exception('an error occured while setting the local file', 0, $e);
     }
     try {
         $iniString = $loader->load();
     } catch (Helper\Exception $e) {
         throw new Exception('an error occured while converting the local file into the cache', 0, $e);
     }
     $this->convertString($iniString);
 }
Ejemplo n.º 3
0
 /**
  *
  */
 public function testGetRemoteVerUrl()
 {
     self::assertSame('http://browscap.org/version', $this->object->getRemoteTimeUrl());
 }
Ejemplo n.º 4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws \UnexpectedValueException
  * @throws \BrowscapPHP\Exception\InvalidArgumentException
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('log-file') && !$input->getOption('log-dir')) {
         throw InvalidArgumentException::oneOfCommandArguments('log-file', 'log-dir');
     }
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $browscap = $this->getBrowscap();
     $loader = new IniLoader();
     $collection = ReaderFactory::factory();
     $fs = new Filesystem();
     $browscap->setLogger($logger)->setCache($this->cache);
     /** @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($this->getFiles($input) as $file) {
         $this->uas = array();
         $path = $this->getPath($file);
         $loader->setLocalFile($path);
         $internalLoader = $loader->getLoader();
         $this->countOk = 0;
         $this->countNok = 0;
         $logger->info('Analyzing file "' . $file->getPathname() . '"');
         if ($internalLoader->isSupportingLoadingLines()) {
             if (!$internalLoader->init($path)) {
                 $logger->info('Skipping empty file "' . $file->getPathname() . '"');
                 continue;
             }
             $this->totalCount = 1;
             while ($internalLoader->isValid()) {
                 $this->handleLine($output, $collection, $browscap, $internalLoader->getLine());
                 $this->totalCount++;
             }
             $internalLoader->close();
             $this->totalCount--;
         } else {
             $lines = file($path);
             if (empty($lines)) {
                 $logger->info('Skipping empty file "' . $file->getPathname() . '"');
                 continue;
             }
             $this->totalCount = count($lines);
             foreach ($lines as $line) {
                 $this->handleLine($output, $collection, $browscap, $line);
             }
         }
         $this->outputProgress($output, '', true);
         arsort($this->uas, SORT_NUMERIC);
         try {
             $fs->dumpFile($input->getArgument('output') . '/output.sql', $this->createSqlContent());
         } catch (IOException $e) {
             // do nothing
         }
         try {
             $fs->dumpFile($input->getArgument('output') . '/output.txt', implode(PHP_EOL, array_unique($this->undefinedClients)));
         } catch (IOException $e) {
             // do nothing
         }
         try {
             $fs->dumpFile($input->getArgument('output') . '/output-with-amount.txt', $this->createAmountContent());
         } catch (IOException $e) {
             // do nothing
         }
         try {
             $fs->dumpFile($input->getArgument('output') . '/output-with-amount-and-type.txt', $this->createAmountTypeContent());
         } catch (IOException $e) {
             // do nothing
         }
     }
     try {
         $fs->dumpFile($input->getArgument('output') . '/output.sql', $this->createSqlContent());
     } catch (IOException $e) {
         // do nothing
     }
     $outputFile = $input->getArgument('output') . '/output.txt';
     try {
         $fs->dumpFile($outputFile, implode(PHP_EOL, array_unique($this->undefinedClients)));
     } catch (IOException $e) {
         throw new \UnexpectedValueException('writing to file "' . $outputFile . '" failed', 0, $e);
     }
     try {
         $fs->dumpFile($input->getArgument('output') . '/output-with-amount.txt', $this->createAmountContent());
     } catch (IOException $e) {
         // do nothing
     }
     try {
         $fs->dumpFile($input->getArgument('output') . '/output-with-amount-and-type.txt', $this->createAmountTypeContent());
     } catch (IOException $e) {
         // do nothing
     }
 }