/**
  * @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()));
 }
 /**
  * @test
  */
 public function itShouldReturnArrayComposerFilesResponse()
 {
     $files = FilesCommittedStub::createAllFiles();
     $composerFilesExtractorQueryHandler = new ComposerFilesExtractorQueryHandler(new ComposerFilesExtractor());
     $composerFilesResponse = $composerFilesExtractorQueryHandler->handle(new ComposerFilesExtractorQuery($files));
     $this->assertTrue($composerFilesResponse->isJsonFile());
     $this->assertTrue($composerFilesResponse->isLockFile());
 }
 /**
  * @test
  */
 public function itShouldReturnJsonFilesResponse()
 {
     $files = FilesCommittedStub::createAllFiles();
     $jsonFilesExtractorQueryHandler = new JsonFilesExtractorQueryHandler(new JsonFilesExtractor());
     $jsonFilesResponse = $jsonFilesExtractorQueryHandler->handle(new JsonFilesExtractorQuery($files));
     $this->assertInstanceOf(JsonFilesResponse::class, $jsonFilesResponse);
     $this->assertSame(1, count($jsonFilesResponse->getFiles()));
 }
 /**
  * @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 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()
 {
     $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);
 }
 /**
  * @test
  */
 public function itShouldExecuteAllTools()
 {
     $files = FilesCommittedStub::createAllFiles();
     $configurationDataResponse = ConfigurationDataResponseStub::createAllEnabled();
     $this->shouldWriteTitle(PreCommitTool::TITLE, 'title');
     $this->shouldGetFilesCommitted($files);
     $this->shouldHandleQuery(new ConfigurationDataFinderQuery(), $configurationDataResponse);
     $this->shouldHandleCommand(new ComposerToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new JsonLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleQuery(new PhpFilesExtractorQuery($files), PhpFilesResponseStub::create(FilesCommittedStub::createWithoutPhpFiles()));
     $this->shouldHandleCommand(new PhpLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new PhpCsToolCommand($files, $configurationDataResponse->getPreCommit()->getPhpCs()->getPhpCsStandard(), HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT));
     $this->shouldHandleCommand(new PhpCsFixerToolCommand($files, $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->getPhpCsFixerOptions(), $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new PhpMdToolCommand($files, $configurationDataResponse->getPreCommit()->getPhpMd()->getPhpMdOptions(), $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new PhpUnitToolCommand($configurationDataResponse->getPreCommit()->getPhpUnit()->isPhpunitRandomMode(), $configurationDataResponse->getPreCommit()->getPhpUnit()->getPhpunitOptions(), $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new StrictCoverageCommand($configurationDataResponse->getPreCommit()->getPhpUnitStrictCoverage()->getMinimum(), $configurationDataResponse->getPreCommit()->getErrorMessage()));
     $this->shouldHandleCommand(new GuardCoverageCommand($configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage()));
     $this->shouldWriteLnOutput(GoodJobLogoResponse::paint($configurationDataResponse->getPreCommit()->getRightMessage()));
     $this->preCommitToolCommandHandler->handle(new PreCommitToolCommand());
 }
 /**
  * @test
  */
 public function itShouldNotExecuteComposerTool()
 {
     $files = FilesCommittedStub::createWithoutComposerFiles();
     $this->shouldHandleQuery(new ComposerFilesExtractorQuery($files), ComposerFilesResponseStub::createNoData());
     $this->composerToolCommandHandler->handle(new ComposerToolCommand($files, $this->errorMessage));
 }
 /**
  * @test
  */
 public function itShouldReturnArrayPhpFilesResponse()
 {
     $files = $this->phpFilesExtractorQueryHandler->handle(new PhpFilesExtractorQuery(FilesCommittedStub::createAllFiles()));
     $this->assertInstanceOf(PhpFilesResponse::class, $files);
     $this->assertSame(5, count($files->getFiles()));
 }