public function execute(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage)
 {
     $outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE);
     $this->output->write($outputMessage->getMessage());
     $this->strictCoverageTool->run($minimumStrictCoverage, $errorMessage);
     $this->output->writeln($outputMessage->getSuccessfulMessage());
 }
 /**
  * @test
  */
 public function itShouldWorksFine()
 {
     $phpCsFixerOptions = PhpCsFixerOptionsStub::random();
     $configurationData = ConfigurationDataResponseStub::createAllEnabled();
     $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
     $outputMessagePsr0 = new PreCommitOutputWriter('Checking psr0 code style with PHP-CS-FIXER');
     $this->shouldWriteOutput($outputMessagePsr0->getMessage());
     foreach ($phpFiles as $file) {
         $this->shouldProcessPhpCsFixerTool($file, 'psr0', $phpCsFixerOptions->value(), null);
     }
     $this->shouldWriteLnOutput($outputMessagePsr0->getSuccessfulMessage());
     $outputMessagePsr1 = new PreCommitOutputWriter('Checking psr1 code style with PHP-CS-FIXER');
     $this->shouldWriteOutput($outputMessagePsr1->getMessage());
     foreach ($phpFiles as $file) {
         $this->shouldProcessPhpCsFixerTool($file, 'psr1', $phpCsFixerOptions->value(), null);
     }
     $this->shouldWriteLnOutput($outputMessagePsr1->getSuccessfulMessage());
     $outputMessagePsr2 = new PreCommitOutputWriter('Checking psr2 code style with PHP-CS-FIXER');
     $this->shouldWriteOutput($outputMessagePsr2->getMessage());
     foreach ($phpFiles as $file) {
         $this->shouldProcessPhpCsFixerTool($file, 'psr2', $phpCsFixerOptions->value(), null);
     }
     $this->shouldWriteLnOutput($outputMessagePsr2->getSuccessfulMessage());
     $outputMessageSymfony = new PreCommitOutputWriter('Checking symfony code style with PHP-CS-FIXER');
     $this->shouldWriteOutput($outputMessageSymfony->getMessage());
     foreach ($phpFiles as $file) {
         $this->shouldProcessPhpCsFixerTool($file, 'symfony', $phpCsFixerOptions->value(), null);
     }
     $this->shouldWriteLnOutput($outputMessageSymfony->getSuccessfulMessage());
     $this->phpCsFixerToolCommandHandler->handle(new PhpCsFixerToolCommand($phpFiles, $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $phpCsFixerOptions->value(), $configurationData->getPreCommit()->getErrorMessage()));
 }
Ejemplo n.º 3
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();
     }
 }
 /**
  * @test
  */
 public function itShouldExecuteAndWorksFine()
 {
     $options = '--testsuite default';
     $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
     $outputMessage = new PreCommitOutputWriter(PhpUnitToolExecutor::EXECUTING_MESSAGE);
     $this->shouldWriteLnOutput($outputMessage->getMessage());
     $this->shouldProcessPhpUnit($options, true);
     $this->phpUnitToolCommandHandler->handle(new PhpUnitToolCommand(true, $options, $errorMessage));
 }
Ejemplo n.º 5
0
 /**
  * @param string $warningMessage
  */
 public function run($warningMessage)
 {
     $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE);
     $this->output->write($outputMessage->getMessage());
     $this->currentCoverage = $this->strictCoverageProcessor->process();
     $this->previousCoverage = $this->guardReader->read();
     true === $this->isLowerCurrentCoverage() ? $this->output->writeln(sprintf("\n<bg=yellow;options=bold>%s Previous coverage %s, current coverage %s.</>", $warningMessage, $this->previousCoverage, $this->currentCoverage)) : $this->output->writeln($outputMessage->getSuccessfulMessage() . $this->printGuardCoverage());
     $this->guardWriter->write($this->currentCoverage);
 }
Ejemplo n.º 6
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 itShouldWorksFine()
 {
     $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.0);
     $outputMessage = new PreCommitOutputWriter(StrictCoverageToolExecutor::EXECUTE_MESSAGE);
     $this->shouldWriteOutput($outputMessage->getMessage());
     $this->shouldProcessStrictCoverage(91.0);
     $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
     $command = new StrictCoverageCommand($minimumStrictCoverage->value(), $this->errorMessage);
     $this->strictCoverageToolCommandHandler->handle($command);
 }
 /**
  * @test
  */
 public function itShouldWorksFine()
 {
     $output = new PreCommitOutputWriter(PhpCsTool::EXECUTE_MESSAGE);
     $files = FilesCommittedStub::createOnlyPhpFiles();
     $this->shouldWriteOutput($output->getMessage());
     foreach ($files as $file) {
         $this->shouldProcessPhpCsTool($file, 'PSR2', null);
     }
     $this->shouldWriteLnOutput($output->getSuccessfulMessage());
     $this->phpCsToolCommandHandler->handle(new PhpCsToolCommand($files, 'PSR2', HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT));
 }
 /**
  * @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));
 }
 /**
  * @test
  */
 public function itShouldWorksFine()
 {
     $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
     $outputMessage = new PreCommitOutputWriter(PhpLintTool::RUNNING_PHPLINT);
     $this->shouldWriteOutput($outputMessage->getMessage());
     foreach ($phpFiles as $file) {
         $this->shouldProcessPhpLintTool($file, null);
     }
     $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
     $this->phpLintToolCommandHandler->handle(new PhpLintToolCommand($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT));
 }
 /**
  * @test
  */
 public function itShouldWorksFine()
 {
     $outputMessage = new PreCommitOutputWriter(GuardCoverageTool::CHECKING_MESSAGE);
     $currentCoverage = 70.0;
     $previousCoverage = 60.0;
     $this->shouldProcessStrictCoverage($currentCoverage);
     $this->shouldWriteOutput($outputMessage->getMessage());
     $this->shouldReadGuardCoverage($previousCoverage);
     $this->shouldWriteLnOutput($this->buildStrictCoverageSuccessfulMessage($currentCoverage, $previousCoverage, $outputMessage->getSuccessfulMessage()));
     $this->shouldWriteGuardCoverage($currentCoverage);
     $this->guardCoverageToolCommandHandler->handle(new GuardCoverageCommand(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT));
 }
 /**
  * @test
  */
 public function itShouldWorksFine()
 {
     $phpMdOptions = PhpMdOptionsStub::random();
     $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
     $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
     $outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE);
     $this->shouldWriteOutput($outputMessage->getMessage());
     foreach ($phpFiles as $phpFile) {
         $this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), null);
     }
     $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
     $command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage);
     $this->phpMdToolCommandHandler->handle($command);
 }
Ejemplo n.º 13
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());
 }
Ejemplo n.º 14
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(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));
 }
Ejemplo n.º 16
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());
 }