/** * @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 itShouldThrowsException() { $this->expectException(InvalidCommitMessageException::class); $configurationDataResponse = ConfigurationDataResponseStub::createCustom(true, true, true); $this->shouldHandleQuery(new ConfigurationDataFinderQuery(), $configurationDataResponse); $this->shouldGetInputFirstArgument('file'); $this->shouldFindCommitMessage('file', 'invalid commit message'); $this->shouldCallIsMerge(false); $this->commitMsgCommandHandler->handle(new CommitMsgCommand($this->getInput())); }
/** * @test */ public function itShouldWorksFine() { $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true); $this->shouldHandleQuery(new ConfigurationDataFinderQuery(), $configurationDataResponse); $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK); $this->shouldExecutePrePushOriginal($this->remote, $this->url, ''); $this->shouldHandleCommand(new PhpUnitToolCommand($configurationDataResponse->getPrePush()->getPhpUnit()->isPhpunitRandomMode(), $configurationDataResponse->getPrePush()->getPhpUnit()->getPhpunitOptions(), $configurationDataResponse->getPrePush()->getErrorMessage())); $this->shouldHandleCommand(new StrictCoverageCommand($configurationDataResponse->getPrePush()->getPhpUnitStrictCoverage()->getMinimum(), $configurationDataResponse->getPrePush()->getErrorMessage())); $this->shouldHandleCommand(new GuardCoverageCommand($configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage())); $this->shouldWriteLnOutput(GoodJobLogoResponse::paint($configurationDataResponse->getPrePush()->getRightMessage())); $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url)); }
/** * @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()); }