Author: Jonathan Stoppani (jonathan@stoppani.name)
Author: Vítor Brandão (noisebleed@noiselabs.org)
Author: Mikołaj Misiurewicz (quentin389+phpb@gmail.com)
Author: Christoph Ziegenberg (christoph@ziegenberg.com)
Author: Thomas Müller (t_mueller_stolzenhain@yahoo.de)
 protected function getParserWithWarmCache($type)
 {
     $filename = 'php_browscap.ini';
     if ($type != '') {
         $filename = $type . '_' . $filename;
     }
     $cache = new \WurflCache\Adapter\Memory();
     $browscap = new Browscap();
     $browscap->setCache($cache);
     $updater = new BrowscapUpdater();
     $updater->setCache($cache);
     $updater->convertFile('tests/resources/browscap/' . $filename);
     return $browscap;
 }
 /**
  * This method is called before the first test of this test class is run.
  *
  * @since Method available since Release 3.4.0
  */
 public static function setUpBeforeClass()
 {
     $objectIniPath = ini_get('browscap');
     if (!is_file($objectIniPath)) {
         self::markTestSkipped('browscap not defined in php.ini');
     }
     // Now, load an INI file into BrowscapPHP\Browscap for testing the UAs
     self::$object = new Browscap();
     $cacheAdapter = new Memory();
     $cache = new BrowscapCache($cacheAdapter);
     $cache->flush();
     $updater = new BrowscapUpdater();
     $updater->setCache($cache)->convertFile($objectIniPath);
     self::$object->setCache($cache);
 }
 /**
  *
  */
 public function testCheckUpdateWithNewerVersion()
 {
     $logger = $this->getMockBuilder(\Monolog\Logger::class)->disableOriginalConstructor()->getMock();
     $this->object->setLogger($logger);
     $body = $this->getMockBuilder(\GuzzleHttp\Psr7\Stream::class)->disableOriginalConstructor()->setMethods(['getContents'])->getMock();
     $body->expects(self::once())->method('getContents')->will(self::returnValue(6001));
     $response = $this->getMockBuilder(\GuzzleHttp\Psr7\Response::class)->disableOriginalConstructor()->setMethods(['getStatusCode', 'getBody'])->getMock();
     $response->expects(self::once())->method('getStatusCode')->will(self::returnValue(200));
     $response->expects(self::once())->method('getBody')->will(self::returnValue($body));
     $client = $this->getMockBuilder(\GuzzleHttp\Client::class)->disableOriginalConstructor()->setMethods(['get'])->getMock();
     $client->expects(self::once())->method('get')->will(self::returnValue($response));
     $this->object->setClient($client);
     $map = [['browscap.time', false, null, null], ['browscap.version', false, null, 6000]];
     $cache = $this->getMockBuilder(\BrowscapPHP\Cache\BrowscapCache::class)->disableOriginalConstructor()->setMethods(['getItem', 'hasItem', 'setItem'])->getMock();
     $cache->expects(self::any())->method('getItem')->will(self::returnValueMap($map));
     $cache->expects(self::any())->method('hasItem')->will(self::returnValue(true));
     $cache->expects(self::never())->method('setItem')->will(self::returnValue(false));
     $this->object->setCache($cache);
     self::assertSame(6000, $this->object->checkUpdate());
 }
Example #4
0
 /**
  * @dataProvider userAgentDataProviderLite
  * @coversNothing
  *
  * @param string $userAgent
  * @param array  $expectedProperties
  *
  * @throws \Exception
  * @throws \BrowscapPHP\Exception
  *
  * @group intergration
  * @group useragenttest
  * @group lite
  */
 public function testUserAgentsLite($userAgent, $expectedProperties)
 {
     if (!is_array($expectedProperties) || !count($expectedProperties)) {
         self::markTestSkipped('Could not run test - no properties were defined to test');
     }
     static $updatedLiteCache = false;
     if (!$updatedLiteCache) {
         self::$browscapUpdater->getCache()->flush();
         self::$browscapUpdater->convertFile(self::$buildFolder . '/lite_php_browscap.ini');
         $updatedLiteCache = true;
     }
     $actualProps = (array) self::$browscap->getBrowser($userAgent);
     foreach ($expectedProperties as $propName => $propValue) {
         if (!self::$propertyHolder->isOutputProperty($propName)) {
             continue;
         }
         if (!self::$propertyHolder->isLiteModeProperty($propName)) {
             continue;
         }
         $propName = strtolower($propName);
         self::assertArrayHasKey($propName, $actualProps, 'Actual result does not have "' . $propName . '" property');
         self::assertSame($propValue, $actualProps[$propName], 'Expected actual "' . $propName . '" to be "' . $propValue . '" (was "' . $actualProps[$propName] . '"; used pattern: ' . $actualProps['browser_name_pattern'] . ')');
     }
 }
Example #5
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $logger->info('initializing converting process');
     $browscap = new BrowscapUpdater();
     $browscap->setLogger($logger)->setCache($this->getCache($input));
     $logger->info('started converting local file');
     $file = $input->getArgument('file') ? $input->getArgument('file') : $this->defaultIniFile;
     $browscap->convertFile($file);
     $logger->info('finished converting local file');
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $logger->debug('started checking for new version of remote file');
     $browscap = new BrowscapUpdater();
     $browscap->setLogger($logger)->setCache($this->getCache($input))->checkUpdate();
     $logger->debug('finished checking for new version of remote file');
 }
Example #7
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $file = $input->getArgument('file');
     if (!$file) {
         $file = $this->defaultIniFile;
     }
     $logger->info('started fetching remote file');
     $browscap = new BrowscapUpdater();
     $browscap->setLogger($logger)->fetch($file, $input->getOption('remote-file'));
     $logger->info('finished fetching remote file');
 }
Example #8
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $logger->info('started updating cache with remote file');
     $browscap = new BrowscapUpdater();
     $browscap->setLogger($logger)->setCache($this->getCache($input))->update($input->getOption('remote-file'));
     $logger->info('finished updating cache with remote file');
 }