/**
  * Test to make sure @see TextDiffTest::provideDiffReporting covers all formats.
  */
 public function testAllFormatsCovered()
 {
     $factory = ReporterFactory::create();
     $formats = $factory->registerBuiltInReporters()->getFormats();
     sort($formats);
     $this->assertSame(array('json', 'junit', 'txt', 'xml'), $formats);
 }
 public function getReporter()
 {
     if (null === $this->reporter) {
         $reporterFactory = ReporterFactory::create();
         $reporterFactory->registerBuiltInReporters();
         if (array_key_exists('format', $this->options)) {
             $format = $this->options['format'];
         } else {
             $format = $this->getConfig()->getFormat();
         }
         try {
             $this->reporter = $reporterFactory->getReporter($format);
         } catch (\UnexpectedValueException $e) {
             throw new InvalidConfigurationException(sprintf('The format "%s" is not defined, supported are %s.', $format, implode(', ', $formats)));
         }
     }
     return $this->reporter;
 }
Beispiel #3
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbosity = $output->getVerbosity();
     $resolver = new ConfigurationResolver();
     $resolver->setCwd(getcwd())->setDefaultConfig($this->defaultConfig)->setOptions(array('allow-risky' => $input->getOption('allow-risky'), 'config' => $input->getOption('config'), 'dry-run' => $input->getOption('dry-run'), 'rules' => $input->getOption('rules'), 'path' => $input->getArgument('path'), 'path-mode' => $input->getOption('path-mode'), 'progress' => OutputInterface::VERBOSITY_VERBOSE <= $verbosity && 'txt' === $input->getOption('format'), 'using-cache' => $input->getOption('using-cache'), 'cache-file' => $input->getOption('cache-file'), 'format' => $input->getOption('format')))->resolve();
     $reporter = ReporterFactory::create()->registerBuiltInReporters()->getReporter($resolver->getFormat());
     $stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : ('txt' === $reporter->getFormat() ? $output : null);
     if (null !== $stdErr && extension_loaded('xdebug')) {
         $stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'You are running php-cs-fixer with xdebug enabled. This has a major impact on runtime performance.'));
     }
     $config = $resolver->getConfig();
     $configFile = $resolver->getConfigFile();
     if (null !== $stdErr && $configFile) {
         $stdErr->writeln(sprintf('Loaded config from "%s".', $configFile));
     }
     $linter = new NullLinter();
     if ($config->usingLinter()) {
         try {
             $linter = new Linter($config->getPhpExecutable());
         } catch (UnavailableLinterException $e) {
             if (null !== $stdErr && $configFile) {
                 $stdErr->writeln('Unable to use linter, can not find PHP executable.');
             }
         }
     }
     if (null !== $stdErr && $config->usingCache()) {
         $cacheFile = $config->getCacheFile();
         if (is_file($cacheFile)) {
             $stdErr->writeln(sprintf('Using cache file "%s".', $cacheFile));
         }
     }
     $showProgress = $resolver->getProgress();
     $runner = new Runner($config, $input->getOption('diff') ? new SebastianBergmannDiffer() : new NullDiffer(), $showProgress ? $this->eventDispatcher : null, $this->errorsManager, $linter, $resolver->isDryRun());
     $progressOutput = $showProgress && $stdErr ? new ProcessOutput($stdErr, $this->eventDispatcher) : new NullOutput();
     $this->stopwatch->start('fixFiles');
     $changed = $runner->fix();
     $this->stopwatch->stop('fixFiles');
     $progressOutput->printLegend();
     $fixEvent = $this->stopwatch->getEvent('fixFiles');
     $reportSummary = ReportSummary::create()->setChanged($changed)->setAddAppliedFixers(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity())->setIsDecoratedOutput($output->isDecorated())->setIsDryRun($resolver->isDryRun())->setMemory($fixEvent->getMemory())->setTime($fixEvent->getDuration());
     $output->write($reporter->generate($reportSummary));
     $invalidErrors = $this->errorsManager->getInvalidErrors();
     $exceptionErrors = $this->errorsManager->getExceptionErrors();
     $lintErrors = $this->errorsManager->getLintErrors();
     if (null !== $stdErr) {
         if (count($invalidErrors) > 0) {
             $this->listErrors($stdErr, 'linting before fixing', $invalidErrors);
         }
         if (count($exceptionErrors) > 0) {
             $this->listErrors($stdErr, 'fixing', $exceptionErrors);
         }
         if (count($lintErrors) > 0) {
             $this->listErrors($stdErr, 'linting after fixing', $lintErrors);
         }
     }
     return $this->calculateExitStatus($resolver->isDryRun(), count($changed) > 0, count($invalidErrors) > 0, count($exceptionErrors) > 0);
 }
Beispiel #4
0
 /**
  * @expectedException        \UnexpectedValueException
  * @expectedExceptionMessage Reporter for format "non_registered_format" is not registered.
  */
 public function testGetNonRegisteredReport()
 {
     $builder = new ReporterFactory();
     $builder->getReporter('non_registered_format');
 }