/** * */ public function testSetGetLoader() { /** @var \FileLoader\Loader $loader */ $loader = $this->getMock('\\FileLoader\\Loader', array(), array(), '', false); self::assertSame($this->object, $this->object->setLoader($loader)); self::assertSame($loader, $this->object->getLoader()); self::assertSame($this->object, $this->object->setLocalFile('test')); self::assertSame($loader, $this->object->getLoader()); }
/** * @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 } }