public function testGenerateComplex() { $expectedXml = <<<'XML' <?xml version="1.0"?> <testsuites> <testsuite assertions="3" errors="0" failures="3" name="PHP CS Fixer" tests="2" time="1.234"> <testcase assertions="2" file="someFile.php" name="someFile"> <failure type="code_style">applied fixers: --------------- * some_fixer_name_here_1 * some_fixer_name_here_2 Diff: --------------- this text is a diff ;)</failure> </testcase> <testcase assertions="1" file="anotherFile.php" name="anotherFile"> <failure type="code_style">applied fixers: --------------- * another_fixer_name_here Diff: --------------- another diff here ;)</failure> </testcase> </testsuite> </testsuites> XML; $actualXml = $this->reporter->generate(ReportSummary::create()->setAddAppliedFixers(true)->setChanged(array('someFile.php' => array('appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'), 'diff' => 'this text is a diff ;)'), 'anotherFile.php' => array('appliedFixers' => array('another_fixer_name_here'), 'diff' => 'another diff here ;)')))->setTime(1234)); $this->assertJunitXmlSchema($actualXml); $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); }
public function testGenerateComplexWithDecoratedOutput() { $expectedText = str_replace("\n", PHP_EOL, <<<'TEXT' 1) someFile.php (<comment>some_fixer_name_here</comment>) <comment> ---------- begin diff ----------</comment> this text is a diff ;) <comment> ----------- end diff -----------</comment> 2) anotherFile.php (<comment>another_fixer_name_here</comment>) <comment> ---------- begin diff ----------</comment> another diff here ;) <comment> ----------- end diff -----------</comment> Checked all files in 1.234 seconds, 2.500 MB memory used TEXT ); $this->assertSame($expectedText, $this->reporter->generate(ReportSummary::create()->setAddAppliedFixers(true)->setChanged(array('someFile.php' => array('appliedFixers' => array('some_fixer_name_here'), 'diff' => 'this text is a diff ;)'), 'anotherFile.php' => array('appliedFixers' => array('another_fixer_name_here'), 'diff' => 'another diff here ;)')))->setIsDecoratedOutput(true)->setIsDryRun(true)->setMemory(2.5 * 1024 * 1024)->setTime(1234))); }
public function testGenerateComplex() { $expectedXml = <<<'XML' <?xml version="1.0" encoding="UTF-8"?> <report> <files> <file id="1" name="someFile.php"> <applied_fixers> <applied_fixer name="some_fixer_name_here"/> </applied_fixers> <diff>this text is a diff ;)</diff> </file> <file id="2" name="anotherFile.php"> <applied_fixers> <applied_fixer name="another_fixer_name_here"/> </applied_fixers> <diff>another diff here ;)</diff> </file> </files> <time unit="s"> <total value="1.234"/> </time> <memory value="2.5" unit="MB"/> </report> XML; $this->assertXmlStringEqualsXmlString($expectedXml, $this->reporter->generate(ReportSummary::create()->setAddAppliedFixers(true)->setChanged(array('someFile.php' => array('appliedFixers' => array('some_fixer_name_here'), 'diff' => 'this text is a diff ;)'), 'anotherFile.php' => array('appliedFixers' => array('another_fixer_name_here'), 'diff' => 'another diff here ;)')))->setMemory(2.5 * 1024 * 1024)->setTime(1234))); }
/** * @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); }
public function testGenerateComplex() { $expectedJson = <<<'JSON' { "files":[ { "name": "someFile.php", "appliedFixers":["some_fixer_name_here"], "diff": "this text is a diff ;)" }, { "name": "anotherFile.php", "appliedFixers":["another_fixer_name_here"], "diff": "another diff here ;)" } ], "memory": 2.5, "time": { "total": 1.234 } } JSON; $this->assertJsonStringEqualsJsonString($expectedJson, $this->reporter->generate(ReportSummary::create()->setAddAppliedFixers(true)->setChanged(array('someFile.php' => array('appliedFixers' => array('some_fixer_name_here'), 'diff' => 'this text is a diff ;)'), 'anotherFile.php' => array('appliedFixers' => array('another_fixer_name_here'), 'diff' => 'another diff here ;)')))->setMemory(2.5 * 1024 * 1024)->setTime(1234))); }