/** * @param bool $jsonFile * @param bool $lockFile * @param string $errorMessage * * @throws ComposerFilesNotFoundException * */ private function executeTool($jsonFile, $lockFile, $errorMessage) { if (true === $jsonFile && false === $lockFile) { $this->output->writeln($this->outputMessage->getFailMessage()); $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); throw new ComposerFilesNotFoundException(); } }
/** * @test */ public function itShouldThrowException() { $this->expectException(ComposerFilesNotFoundException::class); $files = FilesCommittedStub::createInvalidComposerFiles(); $output = new PreCommitOutputWriter(ComposerTool::CHECKING_MESSAGE); $this->shouldWriteOutput($output->getMessage()); $this->shouldHandleQuery(new ComposerFilesExtractorQuery($files), ComposerFilesResponseStub::createInvalidData()); $this->shouldWriteLnOutput($output->getFailMessage()); $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); $this->composerToolCommandHandler->handle(new ComposerToolCommand($files, $this->errorMessage)); }
/** * @param array $files * @param string $errorMessage * * @throws JsonLintViolationsException */ public function execute(array $files, $errorMessage) { $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE); $this->output->write($outputMessage->getMessage()); $errors = []; foreach ($files as $file) { $errors[] = $this->jsonLintProcessor->process($file); } $errors = array_filter($errors); if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputMessage->setError(implode('', $errors))); $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); throw new JsonLintViolationsException(implode('', $errors)); } $this->output->writeln($outputMessage->getSuccessfulMessage()); }
/** * @param array $files * @param string $standard * @param string $errorMessage * * @throws PhpCsViolationException */ public function execute(array $files, $standard, $errorMessage) { $outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE); $this->output->write($outputMessage->getMessage()); $errors = []; foreach ($files as $file) { $errors[] = $this->phpCsToolProcessor->process($file, $standard); } $errors = array_filter($errors); if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputMessage->setError(implode('', $errors))); $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); throw new PhpCsViolationException(); } $this->output->writeln($outputMessage->getSuccessfulMessage()); }
/** * @test */ public function itShouldThrowsException() { $this->expectException(PhpCsViolationException::class); $output = new PreCommitOutputWriter(PhpCsTool::EXECUTE_MESSAGE); $files = FilesCommittedStub::createOnlyPhpFiles(); $this->shouldWriteOutput($output->getMessage()); $errorTxt = null; foreach ($files as $file) { $error = 'ERROR-'; $this->shouldProcessPhpCsTool($file, 'PSR2', $error); $errorTxt .= $error; } $this->shouldWriteLnOutput($output->getFailMessage()); $this->shouldWriteLnOutput($output->setError($errorTxt)); $this->shouldWriteLnOutput(BadJobLogoResponse::paint(HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)); $this->phpCsToolCommandHandler->handle(new PhpCsToolCommand($files, 'PSR2', HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)); }
/** * @test */ public function itShouldThrowsException() { $this->expectException(JsonLintViolationsException::class); $output = new PreCommitOutputWriter(JsonLintToolExecutor::CHECKING_MESSAGE); $jsonFilesResponse = JsonFilesResponseStub::createWithJsonData(); $this->shouldHandleQuery(new JsonFilesExtractorQuery($jsonFilesResponse->getFiles()), $jsonFilesResponse); $this->shouldWriteOutput($output->getMessage()); $errorTxt = null; foreach ($jsonFilesResponse->getFiles() as $file) { $error = 'ERROR'; $this->shouldProcessJsonLint($file, $error); $errorTxt .= $error; } $this->shouldWriteLnOutput($output->getFailMessage()); $this->shouldWriteLnOutput($output->setError($errorTxt)); $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); $this->jsonLintToolCommandHandler->handle(new JsonLintToolCommand($jsonFilesResponse->getFiles(), $this->errorMessage)); }
/** * @param array $files * @param string $level * @param string $options * @param string $errorMessage * * @throws PhpCsFixerViolationsException */ private function executeTool(array $files, $level, $options, $errorMessage) { $outputMessage = new PreCommitOutputWriter(sprintf('Checking %s code style with PHP-CS-FIXER', $level)); $this->output->write($outputMessage->getMessage()); $errors = []; foreach ($files as $file) { $errors[] = $this->phpCsFixerToolProcessor->process($file, $level, $options); } $errors = array_filter($errors); if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $errorsText = $outputMessage->setError(implode('', $errors)); $this->output->writeln($errorsText); $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); throw new PhpCsFixerViolationsException(); } $this->output->writeln($outputMessage->getSuccessfulMessage()); }
/** * @test */ public function itShouldThrowsException() { $this->expectException(PhpCsFixerViolationsException::class); $configurationData = ConfigurationDataResponseStub::createAllEnabled(); $phpFiles = FilesCommittedStub::createOnlyPhpFiles(); $outputMessage = new PreCommitOutputWriter('Checking PSR0 code style with PHP-CS-FIXER'); $this->shouldWriteOutput($outputMessage->getMessage()); $errors = null; foreach ($phpFiles as $file) { $errorText = 'ERROR'; $this->shouldProcessPhpCsFixerTool($file, 'PSR0', $errorText); $errors .= $errorText; } $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errors)); $this->shouldWriteLnOutput(BadJobLogoResponse::paint($configurationData->getPreCommit()->getErrorMessage())); $this->phpCsFixerToolCommandHandler->handle(new PhpCsFixerToolCommand($phpFiles, $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $configurationData->getPreCommit()->getErrorMessage())); }
/** * @test */ public function itShouldThrowsException() { $this->expectException(PhpLintViolationsException::class); $phpFiles = FilesCommittedStub::createOnlyPhpFiles(); $outputMessage = new PreCommitOutputWriter(PhpLintTool::RUNNING_PHPLINT); $errorMessage = PreCommitResponseStub::FIX_YOUR_CODE; $this->shouldWriteOutput($outputMessage->getMessage()); $errors = null; foreach ($phpFiles as $file) { $error = 'ERROR'; $this->shouldProcessPhpLintTool($file, $error); $errors .= $error; } $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errors)); $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); $this->phpLintToolCommandHandler->handle(new PhpLintToolCommand($phpFiles, $errorMessage)); }
/** * @test */ public function itShouldThrowsException() { $this->expectException(PhpMdViolationsException::class); $phpMdOptions = PhpMdOptionsStub::random(); $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; $phpFiles = FilesCommittedStub::createOnlyPhpFiles(); $outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE); $this->shouldWriteOutput($outputMessage->getMessage()); $errorsText = null; foreach ($phpFiles as $phpFile) { $error = 'ERROR'; $this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), $error); $errorsText .= $error; } $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errorsText)); $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); $command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage); $this->phpMdToolCommandHandler->handle($command); }