示例#1
0
 /**
  * @param $type
  * @param $expectedResult
  *
  * @dataProvider dataName
  * @covers ::getName
  */
 public function testName($type, $expectedResult)
 {
     $result = Type::getName($type);
     static::assertSame($expectedResult, $result);
 }
示例#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));
     }
 }