Sets a logger instance
public setLogger ( Psr\Log\LoggerInterface $logger ) : |
||
$logger | Psr\Log\LoggerInterface | |
return |
/** * */ public function testCheckUpdateWithNewerVersion() { $logger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false); $this->object->setLogger($logger); $loader = $this->getMock('\\BrowscapPHP\\Helper\\IniLoader', array('setRemoteFilename', 'setOptions', 'setLogger', 'load', 'getRemoteVersion'), array(), '', false); $loader->expects(self::once())->method('setRemoteFilename')->will(self::returnSelf()); $loader->expects(self::once())->method('setOptions')->will(self::returnSelf()); $loader->expects(self::once())->method('setLogger')->will(self::returnSelf()); $loader->expects(self::never())->method('load')->will(self::returnValue(false)); $loader->expects(self::once())->method('getRemoteVersion')->will(self::returnValue(6001)); $this->object->setLoader($loader); $map = array(array('browscap.time', false, null, null), array('browscap.version', false, null, 6000)); $cache = $this->getMock('\\BrowscapPHP\\Cache\\BrowscapCache', array('getItem', 'hasItem', 'setItem'), array(), '', false); $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()); }
/** * @expectedException \BrowscapPHP\Exception\FetcherException * @expectedExceptionMessage Could not fetch HTTP resource "http://browscap.org/stream?q=PHP_BrowscapINI": */ public function testUpdate() { if (class_exists('\\Browscap\\Browscap')) { self::markTestSkipped('if the \\Browscap\\Browscap class is available the browscap.ini file is not updated from a remote ' . 'location'); } $logger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false); $this->object->setLogger($logger); $loader = $this->getMock('\\BrowscapPHP\\Helper\\IniLoader', array('setRemoteFilename', 'setOptions', 'setLogger', 'load'), array(), '', false); $loader->expects(self::once())->method('setRemoteFilename')->will(self::returnSelf()); $loader->expects(self::once())->method('setOptions')->will(self::returnSelf()); $loader->expects(self::once())->method('setLogger')->will(self::returnSelf()); $loader->expects(self::once())->method('load')->will(self::returnValue(false)); $this->object->setLoader($loader); $this->object->setLoader($loader); $map = array(array('browscap.time', false, null, null), array('browscap.version', false, null, null)); $cache = $this->getMock('\\WurflCache\\Adapter\\Memory', array('getItem'), array(), '', false); $cache->expects(self::any())->method('getItem')->will(self::returnValueMap($map)); $this->object->setCache($cache); $this->object->update(); }
/** * */ public function testSetGetLogger() { $logger = $this->getMockBuilder(\Monolog\Logger::class)->disableOriginalConstructor()->getMock(); self::assertSame($this->object, $this->object->setLogger($logger)); self::assertSame($logger, $this->object->getLogger()); }
/** * @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')); $browscap = new Browscap(); $browscap->setLogger($logger)->setCache($this->getCache($input)); $result = $browscap->getBrowser($input->getArgument('user-agent')); if (!defined('JSON_PRETTY_PRINT')) { // not defined in PHP 5.3 define('JSON_PRETTY_PRINT', 128); } $output->writeln(json_encode($result, JSON_PRETTY_PRINT)); }
/** * @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 = new Browscap(); $loader = new IniLoader(); $collection = ReaderFactory::factory(); $fs = new Filesystem(); $browscap->setLogger($logger)->setCache($this->getCache($input)); /** @var $file \Symfony\Component\Finder\SplFileInfo */ foreach ($this->getFiles($input) as $file) { $this->uas = []; $path = $this->getPath($file); $this->countOk = 0; $this->countNok = 0; $logger->info('Analyzing file "' . $file->getPathname() . '"'); $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.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 } } $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 } }