Exemplo n.º 1
0
 /**
  * @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();
     }
 }
Exemplo n.º 2
0
 /**
  * @param MinimumStrictCoverage $minimumStrictCoverage
  * @param string                $errorMessage
  *
  * @throws InvalidStrictCoverageException
  */
 public function run(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage)
 {
     $currentCoverage = $this->strictCoverageProcessor->process();
     if ($minimumStrictCoverage->value() > $currentCoverage) {
         $this->output->writeln(BadJobLogoResponse::paint($errorMessage));
         throw new InvalidStrictCoverageException($currentCoverage, $minimumStrictCoverage->value());
     }
 }
 /**
  * @test
  */
 public function itShouldThrowsExceptionFromOriginalScript()
 {
     $this->expectException(InvalidPushException::class);
     $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
     $this->shouldHandleQuery(new ConfigurationDataFinderQuery(), $configurationDataResponse);
     $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK);
     $this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error');
     $this->shouldWriteLnOutput(BadJobLogoResponse::paint($configurationDataResponse->getPrePush()->getErrorMessage()));
     $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
 }
Exemplo n.º 4
0
 /**
  * @param string $randomMode
  * @param string $options
  * @param string $errorMessage
  *
  * @throws PhpUnitViolationException
  */
 public function execute($randomMode, $options, $errorMessage)
 {
     $outputMessage = new PreCommitOutputWriter(self::EXECUTING_MESSAGE);
     $this->output->writeln($outputMessage->getMessage());
     $testResult = $this->executeTool($randomMode, $options);
     if (false === $testResult) {
         $this->output->writeln(BadJobLogoResponse::paint($errorMessage));
         throw new PhpUnitViolationException();
     }
 }
 /**
  * @test
  */
 public function itShouldThrowsException()
 {
     $this->expectException(InvalidStrictCoverageException::class);
     $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.0);
     $outputMessage = new PreCommitOutputWriter(StrictCoverageToolExecutor::EXECUTE_MESSAGE);
     $this->shouldWriteOutput($outputMessage->getMessage());
     $this->shouldProcessStrictCoverage(0.0);
     $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
     $command = new StrictCoverageCommand($minimumStrictCoverage->value(), $this->errorMessage);
     $this->strictCoverageToolCommandHandler->handle($command);
 }
 /**
  * @test
  */
 public function itShouldThrowsException()
 {
     $this->expectException(PhpUnitViolationException::class);
     $options = '--testsuite default';
     $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
     $outputMessage = new PreCommitOutputWriter(PhpUnitToolExecutor::EXECUTING_MESSAGE);
     $this->shouldWriteLnOutput($outputMessage->getMessage());
     $this->shouldProcessPhpUnit($options, false);
     $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage));
     $this->phpUnitToolCommandHandler->handle(new PhpUnitToolCommand(true, $options, $errorMessage));
 }
 /**
  * @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));
 }
Exemplo n.º 8
0
 /**
  * @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());
 }
Exemplo n.º 9
0
 /**
  * @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));
 }
Exemplo n.º 12
0
 /**
  * @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);
 }
Exemplo n.º 16
0
 /**
  * @param string $remote
  * @param string $url
  * @param string $errorMessage
  *
  * @throws InvalidPushException
  */
 private function executeOriginalHook($remote, $url, $errorMessage)
 {
     $response = $this->prePushOriginalExecutor->execute($remote, $url);
     if (null != $response) {
         $this->output->writeln(BadJobLogoResponse::paint($errorMessage));
         throw new InvalidPushException();
     }
 }