/** * @param array $expected * @param array $report * @param array $filesStats * * @dataProvider casesReports */ public function testAll(array $expected, array $report, array $filesStats) { $rw = new ReportWrapper($report); $this->tester->assertEquals($expected['countFiles'], $rw->countFiles()); $this->tester->assertEquals($expected['numOfErrors'], $rw->numOfErrors()); $this->tester->assertEquals($expected['numOfWarnings'], $rw->numOfWarnings()); $this->tester->assertEquals($expected['highestSeverity'], $rw->highestSeverity()); /** * @var string $filePath * @var \Cheppers\Robo\ScssLint\LintReportWrapper\FileWrapper $fw */ foreach ($rw->yieldFiles() as $filePath => $fw) { $fileStats = $filesStats[$filePath]; $this->tester->assertEquals($filePath, $fw->filePath()); $this->tester->assertEquals($fileStats['numOfErrors'], $fw->numOfErrors()); $this->tester->assertEquals($fileStats['numOfWarnings'], $fw->numOfWarnings()); $this->tester->assertEquals($fileStats['highestSeverity'], $fw->highestSeverity()); $this->tester->assertEquals($fileStats['stats'], $fw->stats()); /** * @var int $i * @var \Cheppers\LintReport\FailureWrapperInterface $failureWrapper */ foreach ($fw->yieldFailures() as $i => $failureWrapper) { $failure = $report[$filePath][$i]; $this->tester->assertEquals($failure['severity'], $failureWrapper->severity()); $this->tester->assertEquals($failure['linter'], $failureWrapper->source()); $this->tester->assertEquals($failure['line'], $failureWrapper->line()); $this->tester->assertEquals($failure['column'], $failureWrapper->column()); $this->tester->assertEquals($failure['reason'], $failureWrapper->message()); } } }
/** * TaskScssLintRun class run function. */ public function run() { $command = $this->buildCommand(); $this->printTaskInfo(sprintf('SCSS lint task runs: <info>%s</info>', $command)); $lintReporters = $this->initLintReporters(); if ($lintReporters && $this->format !== 'JSON') { $this->exitCode = static::EXIT_CODE_INVALID; return new Result($this, $this->exitCode, $this->getExitMessage($this->exitCode)); } /** @var Process $process */ $process = new $this->processClass($command); if ($this->workingDirectory) { $process->setWorkingDirectory($this->workingDirectory); } $this->startTimer(); $this->exitCode = $process->run(); $this->stopTimer(); $numOfErrors = $this->exitCode; $numOfWarnings = 0; if ($this->isLintSuccess()) { $originalOutput = $process->getOutput(); if ($this->format === 'JSON') { $jsonOutput = $this->out ? file_get_contents($this->out) : $originalOutput; $reportWrapper = new ReportWrapper(json_decode($jsonOutput, true)); $numOfErrors = $reportWrapper->numOfErrors(); $numOfWarnings = $reportWrapper->numOfWarnings(); if ($this->isReportHasToBePutBackIntoJar()) { $this->setAssetJarValue('report', $reportWrapper); } foreach ($lintReporters as $lintReporter) { $lintReporter->setReportWrapper($reportWrapper)->generate(); } } if (!$lintReporters) { $this->output()->write($originalOutput); } } $exitCode = $this->getTaskExitCode($numOfErrors, $numOfWarnings); return new Result($this, $exitCode, $this->getExitMessage($exitCode) ?: $process->getErrorOutput(), ['time' => $this->getExecutionTime()]); }