public function testConfigurationIsLoadedAndProcessedWithDefaultConfigFile() { $distConfig = ['foo' => 'bar']; $mergedConfig = $distConfig; $configuration = $this->getMockBuilder('Helmich\\TypoScriptLint\\Linter\\LinterConfiguration')->disableOriginalConstructor()->getMock(); $configuration->expects($this->once())->method('setConfiguration')->with($mergedConfig); $this->loader->expects($this->once())->method('load')->with('tslint.dist.yml')->willReturn($distConfig); $this->processor->expects($this->once())->method('processConfiguration')->with($this->isInstanceOf('Helmich\\TypoScriptLint\\Linter\\LinterConfiguration'), [$distConfig, []])->willReturn($mergedConfig); /** @noinspection PhpParamsInspection */ $loadedConfiguration = $this->locator->loadConfiguration(NULL, $configuration); $this->assertSame($loadedConfiguration, $configuration); }
/** * Executes this command. * * @param \Symfony\Component\Console\Input\InputInterface $input Input options. * @param \Symfony\Component\Console\Output\OutputInterface $output Output stream. * @return void * * @throws \Helmich\TypoScriptLint\Exception\BadOutputFileException */ protected function execute(InputInterface $input, OutputInterface $output) { $filenames = $input->getArgument('filename'); $outputTarget = $input->getOption('output'); $exitWithExitCode = $input->getOption('exit-code'); if (FALSE == $outputTarget) { throw new BadOutputFileException('Bad output file.'); } $reportOutput = $input->getOption('output') === '-' ? $output : new StreamOutput(fopen($input->getOption('output'), 'w')); $configuration = $this->linterConfigurationLocator->loadConfiguration($input->getOption('config')); $printer = $this->printerLocator->createPrinter($input->getOption('format'), $reportOutput); $report = new Report(); foreach ($this->finder->getFilenames($filenames) as $filename) { $output->writeln("Linting input file <comment>{$filename}</comment>."); $this->linter->lintFile($filename, $report, $configuration, $output); } $printer->writeReport($report); if ($exitWithExitCode) { $exitCode = $report->countWarnings() > 0 ? 2 : 0; $this->eventDispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) use($exitCode) { $event->setExitCode($exitCode); }); } }