Ejemplo n.º 1
0
 /**
  * @expectedException \Crossjoin\Browscap\Exception\ParserRuntimeException
  *
  * @covers ::update
  *
  * @throws InvalidArgumentException
  * @throws ParserConfigurationException
  * @throws ParserRuntimeException
  * @throws SourceUnavailableException
  */
 public function testUpdateLoop()
 {
     $reader = $this->getMockBuilder('\\Crossjoin\\Browscap\\Parser\\Sqlite\\Reader')->disableOriginalConstructor()->setMethods(['isUpdateRequired'])->getMock();
     $reader->expects(static::any())->method('isUpdateRequired')->willReturn(true);
     $parser = $this->getMockBuilder('\\Crossjoin\\Browscap\\Parser\\Sqlite\\Parser')->disableOriginalConstructor()->setMethods(['getReader'])->getMock();
     $parser->expects(static::any())->method('getReader')->willReturn($reader);
     $iniFile = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'lite_php_browscap.ini';
     $source = new File($iniFile);
     /** @var \Crossjoin\Browscap\Parser\Sqlite\Parser $parser */
     $parser->setSource($source);
     $browscap = new Browscap();
     $browscap->setParser($parser);
     $browscap->update(true);
 }
Ejemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  * @throws ParserConfigurationException
  * @throws ParserRuntimeException
  * @throws SourceConditionNotSatisfiedException
  * @throws SourceUnavailableException
  * @throws UnexpectedValueException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $browscap = new Browscap();
     // Set source
     $source = null;
     if ($input->getOption('ini-php')) {
         $source = new PhpSetting();
     } elseif ($input->getOption('ini-load')) {
         $type = Type::STANDARD;
         switch ($input->getOption('ini-load')) {
             case 'lite':
                 $type = Type::LITE;
                 break;
             case 'full':
                 $type = Type::FULL;
                 break;
         }
         $source = new BrowscapOrg($type);
     } elseif ($input->getOption('ini-file')) {
         $file = (string) $input->getOption('ini-file');
         $source = new File($file);
     }
     if ($source !== null) {
         $browscap->getParser()->setSource($source);
     }
     // Set filter
     $filter = null;
     if ($input->getOption('filter-allowed')) {
         $properties = (array) $input->getOption('filter-allowed');
         $filter = new Allowed($properties);
     } elseif ($input->getOption('filter-disallowed')) {
         $properties = (array) $input->getOption('filter-disallowed');
         $filter = new Disallowed($properties);
     }
     if ($filter !== null) {
         $browscap->getParser()->setPropertyFilter($filter);
     }
     // Set data directory
     if ($input->getOption('dir')) {
         /** @var Parser $parser */
         $parser = $browscap->getParser();
         $parser->setDataDirectory((string) $input->getOption('dir'));
     }
     // Force an update?
     $force = false;
     if ($input->getOption('force')) {
         $force = true;
     }
     // Process update
     $output->writeln('Processing update...');
     $updated = $browscap->update($force);
     // Output result
     $version = $browscap->getParser()->getReader()->getVersion();
     $type = $browscap->getParser()->getReader()->getType();
     $name = Type::getName($type);
     if ($updated === true) {
         $output->writeln(sprintf('Browscap data successfully updated. New version: %s (%s)', $version, $name));
     } else {
         $output->writeln(sprintf('Nothing to update. Current version: %s (%s)', $version, $name));
     }
 }