diff --git a/.gitignore b/.gitignore index 740d2d9..974ada3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ composer.phar vendor/ bin/ +.idea/ php-git-hooks.yml # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file @@ -9,7 +10,6 @@ composer.lock .guard_coverage var/cache var/logs -.php_cs.cache ###> friendsofphp/php-cs-fixer ### .php_cs diff --git a/php-git-hooks.yml.sample b/php-git-hooks.yml.sample index 5ed7b55..e50c429 100644 --- a/php-git-hooks.yml.sample +++ b/php-git-hooks.yml.sample @@ -29,6 +29,7 @@ pre-commit: options: '' composer: true message: + enable-faces: true right-message: 'HEY, GOOD JOB!!' error-message: 'FIX YOUR CODE!!' commit-msg: @@ -48,5 +49,6 @@ pre-push: enabled: true message: 'WARNING!!, your code coverage is lower.' message: + enable-faces: true right-message: 'PUSH IT!!' error-message: 'YOU CAN NOT PUSH CODE!!' diff --git a/src/PhpGitHooks/Infrastructure/Composer/ConfiguratorScript.php b/src/PhpGitHooks/Infrastructure/Composer/ConfiguratorScript.php index 0bd5b96..a6d6307 100644 --- a/src/PhpGitHooks/Infrastructure/Composer/ConfiguratorScript.php +++ b/src/PhpGitHooks/Infrastructure/Composer/ConfiguratorScript.php @@ -18,8 +18,6 @@ class ConfiguratorScript { /** * @param Event $event - * - * @return mixed */ public static function buildConfig(Event $event) { diff --git a/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerTool.php b/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerTool.php index af6750e..a2e9c0c 100644 --- a/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerTool.php +++ b/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerTool.php @@ -14,17 +14,23 @@ class ComposerTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * ComposerToolCommand constructor. * - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct(array $files, $errorMessage) + public function __construct(array $files, $errorMessage, $enableFaces) { $this->files = $files; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -35,6 +41,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return array */ diff --git a/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerToolHandler.php b/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerToolHandler.php index 4130f5d..8fc625b 100644 --- a/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerToolHandler.php +++ b/src/PhpGitHooks/Module/Composer/Contract/Command/ComposerToolHandler.php @@ -43,19 +43,22 @@ public function __construct( /** * @param CommandInterface|ComposerTool $command + * + * @throws ComposerFilesNotFoundException */ public function handle(CommandInterface $command) { - $this->execute($command->getFiles(), $command->getErrorMessage()); + $this->execute($command->getFiles(), $command->getErrorMessage(), $command->isEnableFaces()); } /** - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces * * @throws ComposerFilesNotFoundException */ - private function execute(array $files, $errorMessage) + private function execute(array $files, $errorMessage, $enableFaces) { $composerFilesResponse = $this->getComposerFilesResponse($files); @@ -66,24 +69,26 @@ private function execute(array $files, $errorMessage) $this->executeTool( $composerFilesResponse->isJsonFile(), $composerFilesResponse->isLockFile(), - $errorMessage + $errorMessage, + $enableFaces ); $this->output->writeln($this->outputMessage->getSuccessfulMessage()); } } /** - * @param bool $jsonFile - * @param bool $lockFile + * @param bool $jsonFile + * @param bool $lockFile * @param string $errorMessage + * @param bool $enableFaces * * @throws ComposerFilesNotFoundException * */ - private function executeTool($jsonFile, $lockFile, $errorMessage) + private function executeTool($jsonFile, $lockFile, $errorMessage, $enableFaces) { if (true === $jsonFile && false === $lockFile) { $this->output->writeln($this->outputMessage->getFailMessage()); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new ComposerFilesNotFoundException(); } } diff --git a/src/PhpGitHooks/Module/Composer/Tests/Behaviour/ComposerToolHandlerTest.php b/src/PhpGitHooks/Module/Composer/Tests/Behaviour/ComposerToolHandlerTest.php index 49d40e4..6dab76a 100644 --- a/src/PhpGitHooks/Module/Composer/Tests/Behaviour/ComposerToolHandlerTest.php +++ b/src/PhpGitHooks/Module/Composer/Tests/Behaviour/ComposerToolHandlerTest.php @@ -35,6 +35,7 @@ protected function setUp() /** * @test + * @throws ComposerFilesNotFoundException */ public function itShouldWorksFine() { @@ -49,12 +50,13 @@ public function itShouldWorksFine() $this->shouldWriteLnOutput($output->getSuccessfulMessage()); $this->composerToolCommandHandler->handle( - new ComposerTool($files, $this->errorMessage) + new ComposerTool($files, $this->errorMessage, true) ); } /** * @test + * @throws ComposerFilesNotFoundException */ public function itShouldThrowException() { @@ -69,15 +71,16 @@ public function itShouldThrowException() ComposerFilesResponseStub::createInvalidData() ); $this->shouldWriteLnOutput($output->getFailMessage()); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage, true)); $this->composerToolCommandHandler->handle( - new ComposerTool($files, $this->errorMessage) + new ComposerTool($files, $this->errorMessage, true) ); } /** * @test + * @throws ComposerFilesNotFoundException */ public function itShouldNotExecuteComposerTool() { @@ -88,6 +91,6 @@ public function itShouldNotExecuteComposerTool() ComposerFilesResponseStub::createNoData() ); - $this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage)); + $this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage, true)); } } diff --git a/src/PhpGitHooks/Module/Configuration/Contract/Response/PreCommitResponse.php b/src/PhpGitHooks/Module/Configuration/Contract/Response/PreCommitResponse.php index 197b435..2ed7e3d 100644 --- a/src/PhpGitHooks/Module/Configuration/Contract/Response/PreCommitResponse.php +++ b/src/PhpGitHooks/Module/Configuration/Contract/Response/PreCommitResponse.php @@ -16,6 +16,10 @@ class PreCommitResponse * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * @var bool */ @@ -56,23 +60,25 @@ class PreCommitResponse /** * PreCommitResponse constructor. * - * @param bool $preCommit - * @param string $rightMessage - * @param string $errorMessage - * @param bool $composer - * @param bool $jsonLint - * @param bool $phpLint - * @param PhpMdResponse $phpMd - * @param PhpCsResponse $phpCs - * @param PhpCsFixerResponse $phpCsFixer - * @param PhpUnitResponse $phpUnit + * @param bool $preCommit + * @param string $rightMessage + * @param string $errorMessage + * @param bool $enableFaces + * @param bool $composer + * @param bool $jsonLint + * @param bool $phpLint + * @param PhpMdResponse $phpMd + * @param PhpCsResponse $phpCs + * @param PhpCsFixerResponse $phpCsFixer + * @param PhpUnitResponse $phpUnit * @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverage - * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage + * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage */ public function __construct( $preCommit, $rightMessage, $errorMessage, + $enableFaces, $composer, $jsonLint, $phpLint, @@ -86,6 +92,7 @@ public function __construct( $this->preCommit = $preCommit; $this->rightMessage = $rightMessage; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; $this->composer = $composer; $this->jsonLint = $jsonLint; $this->phpLint = $phpLint; @@ -121,6 +128,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return bool */ diff --git a/src/PhpGitHooks/Module/Configuration/Contract/Response/PrePushResponse.php b/src/PhpGitHooks/Module/Configuration/Contract/Response/PrePushResponse.php index 9b6dc11..5b9229e 100644 --- a/src/PhpGitHooks/Module/Configuration/Contract/Response/PrePushResponse.php +++ b/src/PhpGitHooks/Module/Configuration/Contract/Response/PrePushResponse.php @@ -24,6 +24,10 @@ class PrePushResponse * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * @var PhpUnitGuardCoverageResponse */ @@ -32,17 +36,19 @@ class PrePushResponse /** * PrePushResponse constructor. * - * @param bool $prePush - * @param string $rightMessage - * @param string $errorMessage - * @param PhpUnitResponse $phpUnit + * @param bool $prePush + * @param string $rightMessage + * @param string $errorMessage + * @param bool $enableFaces + * @param PhpUnitResponse $phpUnit * @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverage - * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage + * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverage */ public function __construct( $prePush, $rightMessage, $errorMessage, + $enableFaces, PhpUnitResponse $phpUnit, PhpUnitStrictCoverageResponse $phpUnitStrictCoverage, PhpUnitGuardCoverageResponse $phpUnitGuardCoverage @@ -52,6 +58,7 @@ public function __construct( $this->prePush = $prePush; $this->rightMessage = $rightMessage; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; $this->phpUnitGuardCoverage = $phpUnitGuardCoverage; } @@ -95,6 +102,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return string + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return PhpUnitGuardCoverageResponse */ diff --git a/src/PhpGitHooks/Module/Configuration/Domain/Messages.php b/src/PhpGitHooks/Module/Configuration/Domain/Messages.php index e31d78f..9a7d030 100644 --- a/src/PhpGitHooks/Module/Configuration/Domain/Messages.php +++ b/src/PhpGitHooks/Module/Configuration/Domain/Messages.php @@ -13,16 +13,23 @@ class Messages */ private $errorMessage; + /** + * @var Enabled + */ + private $enableFaces; + /** * Messages constructor. * * @param Message $rightMessage * @param Message $errorMessage + * @param Enabled $enableFaces */ - public function __construct(Message $rightMessage, Message $errorMessage) + public function __construct(Message $rightMessage, Message $errorMessage, Enabled $enableFaces) { $this->rightMessage = $rightMessage; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -41,6 +48,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return Enabled + */ + public function getEnableFaces() + { + return $this->enableFaces; + } + /** * @return Messages */ @@ -48,7 +63,8 @@ public function disable() { return new self( new Message(null), - new Message(null) + new Message(null), + new Enabled(true) ); } } diff --git a/src/PhpGitHooks/Module/Configuration/Service/ConfigurationArrayTransformer.php b/src/PhpGitHooks/Module/Configuration/Service/ConfigurationArrayTransformer.php index af93e54..75f91df 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/ConfigurationArrayTransformer.php +++ b/src/PhpGitHooks/Module/Configuration/Service/ConfigurationArrayTransformer.php @@ -89,6 +89,7 @@ public static function transform(PreCommit $preCommit, CommitMsg $commitMsg, Pre ], ], 'message' => [ + 'enable-faces' => $preCommit->getMessages()->getEnableFaces()->value(), 'right-message' => $preCommit->getMessages()->getRightMessage()->value(), 'error-message' => $preCommit->getMessages()->getErrorMessage()->value(), ], @@ -115,6 +116,7 @@ public static function transform(PreCommit $preCommit, CommitMsg $commitMsg, Pre ], ], 'message' => [ + 'enable-faces' => $preCommit->getMessages()->getEnableFaces()->value(), 'right-message' => $prePush->getMessages()->getRightMessage()->value(), 'error-message' => $prePush->getMessages()->getErrorMessage()->value(), ], diff --git a/src/PhpGitHooks/Module/Configuration/Service/ConfigurationDataResponseFactory.php b/src/PhpGitHooks/Module/Configuration/Service/ConfigurationDataResponseFactory.php index 35cdf3f..ddcef2b 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/ConfigurationDataResponseFactory.php +++ b/src/PhpGitHooks/Module/Configuration/Service/ConfigurationDataResponseFactory.php @@ -72,6 +72,7 @@ public static function build( $prePush->isEnabled(), $prePush->getMessages()->getRightMessage(), $prePush->getMessages()->getErrorMessage(), + $prePush->getMessages()->getEnableFaces()->value(), new PhpUnitResponse( $prePushPhpUnit->isEnabled(), $prePushPhpUnit->getRandomMode()->value(), @@ -91,6 +92,7 @@ public static function build( $preCommit->isEnabled(), $preCommit->getMessages()->getRightMessage()->value(), $preCommit->getMessages()->getErrorMessage()->value(), + $preCommit->getMessages()->getEnableFaces()->value(), $composer->isEnabled(), $jsonLint->isEnabled(), $phpLint->isEnabled(), diff --git a/src/PhpGitHooks/Module/Configuration/Service/HookQuestions.php b/src/PhpGitHooks/Module/Configuration/Service/HookQuestions.php index ff4d6d6..9288c87 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/HookQuestions.php +++ b/src/PhpGitHooks/Module/Configuration/Service/HookQuestions.php @@ -12,6 +12,7 @@ class HookQuestions const PRE_COMMIT_ERROR_MESSAGE = 'Write an error message for pre-commit hook: '. ''.self::PRE_COMMIT_ERROR_MESSAGE_DEFAULT.''; const PRE_COMMIT_ERROR_MESSAGE_DEFAULT = 'FIX YOUR FUCKING CODE!!'; + const PRE_COMMIT_ENABLE_FACES_MESSAGE = 'Enable face in messages for pre-commit hook?: [Y/n]'; const COMPOSER_TOOL = 'Do you want enable COMPOSER tool?: [Y/n]'; const JSONLINT_TOOL = 'Do you want enable JSONLINT tool?: [Y/n]'; const PHPLINT_TOOL = 'Do you want enable PHPLINT tool?: [Y/n]'; @@ -43,6 +44,7 @@ class HookQuestions const PRE_PUSH_ERROR_MESSAGE_DEFAULT = 'YOU CAN NOT PUSH CODE!!'; const PRE_PUSH_ERROR_MESSAGE = 'Write an error message for pre-push hook: '. ''.self::PRE_PUSH_ERROR_MESSAGE_DEFAULT.''; + const PRE_PUSH_ENABLE_FACES_MESSAGE = 'Enable face in messages for pre-push hook?: [Y/n]'; const PHPUNIT_STRICT_COVERAGE = 'Do you want enable STRICT COVERAGE tool?: [Y/n]'; const PHPUNIT_STRICT_COVERAGE_MINIMUM = 'Write minimum coverage to guard: [0.00]'; const PHPUNIT_GUARD_COVERAGE = 'Do you want enable GUARD COVERAGE tool?: [Y/n]'; diff --git a/src/PhpGitHooks/Module/Configuration/Service/MessagesFactory.php b/src/PhpGitHooks/Module/Configuration/Service/MessagesFactory.php index 56431b6..bbba085 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/MessagesFactory.php +++ b/src/PhpGitHooks/Module/Configuration/Service/MessagesFactory.php @@ -2,6 +2,7 @@ namespace PhpGitHooks\Module\Configuration\Service; +use PhpGitHooks\Module\Configuration\Domain\Enabled; use PhpGitHooks\Module\Configuration\Domain\Message; use PhpGitHooks\Module\Configuration\Domain\Messages; @@ -16,7 +17,8 @@ public static function fromArray(array $data) { return new Messages( new Message(isset($data['right-message']) ? $data['right-message'] : ''), - new Message(isset($data['error-message']) ? $data['error-message'] : '') + new Message(isset($data['error-message']) ? $data['error-message'] : ''), + new Enabled(isset($data['error-message']) ? (bool)$data['error-message'] : true) ); } @@ -27,7 +29,8 @@ public static function setUndefined() { return new Messages( new Message(null), - new Message(null) + new Message(null), + new Enabled(true) ); } } diff --git a/src/PhpGitHooks/Module/Configuration/Service/PreCommitConfigurator.php b/src/PhpGitHooks/Module/Configuration/Service/PreCommitConfigurator.php index b050f0c..b7c688f 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/PreCommitConfigurator.php +++ b/src/PhpGitHooks/Module/Configuration/Service/PreCommitConfigurator.php @@ -27,10 +27,13 @@ public static function configure(IOInterface $io, PreCommit $preCommit) ->ask(HookQuestions::PRE_COMMIT_RIGHT_MESSAGE, HookQuestions::PRE_COMMIT_RIGHT_MESSAGE_DEFAULT); $errorMessageAnswer = $io ->ask(HookQuestions::PRE_COMMIT_ERROR_MESSAGE, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT); + $enableFaces = $io + ->ask(HookQuestions::PRE_COMMIT_ENABLE_FACES_MESSAGE, HookQuestions::DEFAULT_TOOL_ANSWER); $preCommit = $preCommit->setMessages(new Messages( new Message($rightMessageAnswer), - new Message($errorMessageAnswer) + new Message($errorMessageAnswer), + new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($enableFaces)) )); } diff --git a/src/PhpGitHooks/Module/Configuration/Service/PrePushConfigurator.php b/src/PhpGitHooks/Module/Configuration/Service/PrePushConfigurator.php index 6044a22..e604766 100644 --- a/src/PhpGitHooks/Module/Configuration/Service/PrePushConfigurator.php +++ b/src/PhpGitHooks/Module/Configuration/Service/PrePushConfigurator.php @@ -21,11 +21,14 @@ public static function configure(IOInterface $input, PrePush $prePush) ->ask(HookQuestions::PRE_PUSH_RIGHT_MESSAGE, HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT); $errorMessageAnswer = $input ->ask(HookQuestions::PRE_PUSH_ERROR_MESSAGE, HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT); + $enableFaces = $input + ->ask(HookQuestions::PRE_PUSH_ENABLE_FACES_MESSAGE, HookQuestions::DEFAULT_TOOL_ANSWER); $prePush = $prePush->setMessages( new Messages( new Message($rightMessageAnswer), - new Message($errorMessageAnswer) + new Message($errorMessageAnswer), + new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($enableFaces)) ) ); } diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/ConfigurationProcessorHandlerTest.php b/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/ConfigurationProcessorHandlerTest.php index 98acfa4..70b4d66 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/ConfigurationProcessorHandlerTest.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/ConfigurationProcessorHandlerTest.php @@ -74,6 +74,11 @@ public function itShouldMakeAllQuestions() HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, ConfigArrayDataStub::ERROR_MESSAGE ); + $this->shouldAsk( + HookQuestions::PRE_COMMIT_ENABLE_FACES_MESSAGE, + HookQuestions::DEFAULT_TOOL_ANSWER, + $yes + ); $this->shouldAsk(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); $this->shouldAsk(HookQuestions::JSONLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); $this->shouldAsk(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); @@ -121,6 +126,11 @@ public function itShouldMakeAllQuestions() HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT, HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT ); + $this->shouldAsk( + HookQuestions::PRE_PUSH_ENABLE_FACES_MESSAGE, + HookQuestions::DEFAULT_TOOL_ANSWER, + $yes + ); $this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); $this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); $this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS); diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/PreCommitProcessorTest.php b/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/PreCommitProcessorTest.php index 11b8b4c..709f4d5 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/PreCommitProcessorTest.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Behaviour/PreCommitProcessorTest.php @@ -50,6 +50,7 @@ public function itShouldDisablePreCommitHook() $this->assertFalse($preCommitData->isUndefined()); $this->assertNull($preCommitData->getMessages()->getRightMessage()->value()); $this->assertNull($preCommitData->getMessages()->getErrorMessage()->value()); + $this->assertTrue($preCommitData->getMessages()->getEnableFaces()->value()); /** @var Execute $execute */ $execute = $preCommitData->getExecute(); diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigArrayDataStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigArrayDataStub.php index b8e089c..6f0513d 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigArrayDataStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigArrayDataStub.php @@ -62,6 +62,7 @@ public static function hooksEnabledWithEnabledTools() ], ], 'message' => [ + 'enable-faces' => true, 'right-message' => static::RIGHT_MESSAGE, 'error-message' => static::ERROR_MESSAGE, ], @@ -88,6 +89,7 @@ public static function hooksEnabledWithEnabledTools() ] ], 'message' => [ + 'enable-faces' => true, 'right-message' => HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT, 'error-message' => HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT, ] diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigurationDataResponseStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigurationDataResponseStub.php index 7f38497..af85ab3 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigurationDataResponseStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/ConfigurationDataResponseStub.php @@ -50,6 +50,7 @@ public static function createCustom($preCommit, $commitMsg, $prePush) $preCommit, PreCommitResponseStub::GOOD_JOB, PreCommitResponseStub::FIX_YOUR_CODE, + true, $preCommit, $preCommit, $preCommit, @@ -65,6 +66,7 @@ public static function createCustom($preCommit, $commitMsg, $prePush) $prePush, PrePushResponseStub::RIGHT_MESSAGE, PrePushResponseStub::ERROR_MESSAGE, + true, PhpUnitResponseStub::create($prePush, $prePush, PhpUnitResponseStub::OPTIONS), PhpUnitStrictCoverageResponseStub::create($prePush, PhpUnitStrictCoverageResponseStub::MINIMUM), PhpUnitGuardCoverageResponseStub::create($prePush, PhpUnitGuardCoverageResponseStub::WARNING_MESSAGE) diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/MessagesStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/MessagesStub.php index 860833b..684c5a4 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/MessagesStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/MessagesStub.php @@ -2,6 +2,7 @@ namespace PhpGitHooks\Module\Configuration\Tests\Stub; +use PhpGitHooks\Module\Configuration\Domain\Enabled; use PhpGitHooks\Module\Configuration\Domain\Message; use PhpGitHooks\Module\Configuration\Domain\Messages; use PhpGitHooks\Module\Tests\Infrastructure\Stub\RandomStubInterface; @@ -11,14 +12,13 @@ class MessagesStub implements RandomStubInterface /** * @param Message $rightMessage * @param Message $errorMessage + * @param Enabled $enableFaces * * @return Messages */ - public static function create( - Message $rightMessage, - Message $errorMessage - ) { - return new Messages($rightMessage, $errorMessage); + public static function create(Message $rightMessage, Message $errorMessage, Enabled $enableFaces) + { + return new Messages($rightMessage, $errorMessage, $enableFaces); } /** @@ -26,6 +26,6 @@ public static function create( */ public static function random() { - return self::create(MessageStub::random(), MessageStub::random()); + return self::create(MessageStub::random(), MessageStub::random(), EnabledStub::random()); } } diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitResponseStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitResponseStub.php index 467afb9..5f94666 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitResponseStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitResponseStub.php @@ -18,18 +18,19 @@ class PreCommitResponseStub const MINIMUM_COVERAGE = 100.00; /** - * @param bool $preCommit - * @param string $rightMessage - * @param string $errorMessage - * @param bool $composer - * @param bool $jsonLint - * @param bool $phpLint - * @param PhpMdResponse $pmdResponse - * @param PhpCsResponse $phpCsResponse - * @param PhpCsFixerResponse $phpCsFixerResponse - * @param PhpUnitResponse $phpUnitResponse + * @param bool $preCommit + * @param string $rightMessage + * @param string $errorMessage + * @param bool $enableFaces + * @param bool $composer + * @param bool $jsonLint + * @param bool $phpLint + * @param PhpMdResponse $pmdResponse + * @param PhpCsResponse $phpCsResponse + * @param PhpCsFixerResponse $phpCsFixerResponse + * @param PhpUnitResponse $phpUnitResponse * @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverageResponse - * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverageResponse + * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverageResponse * * @return PreCommitResponse */ @@ -37,6 +38,7 @@ public static function create( $preCommit, $rightMessage, $errorMessage, + $enableFaces, $composer, $jsonLint, $phpLint, @@ -51,6 +53,7 @@ public static function create( $preCommit, $rightMessage, $errorMessage, + $enableFaces, $composer, $jsonLint, $phpLint, @@ -77,6 +80,7 @@ public static function createAllEnabled() $bool, $bool, $bool, + $bool, PhpMdResponseStub::createEnabled(), PhpCsResponseStub::createEnabled(), PhpCsFixerResponseStub::createEnabled(), diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitStub.php index b8eca9a..214ee26 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PreCommitStub.php @@ -89,7 +89,11 @@ public static function createAllEnabled() PhpUnitStrictCoverageStub::createEnabled(), PhpUnitGuardCoverageStub::createEnabled('fix') ), - MessagesStub::create(MessageStub::create('ok'), MessageStub::create('fix')) + MessagesStub::create( + MessageStub::create('ok'), + MessageStub::create('fix'), + EnabledStub::create(true) + ) ); } } diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushResponseStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushResponseStub.php index 16ba613..713c4e5 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushResponseStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushResponseStub.php @@ -13,12 +13,13 @@ class PrePushResponseStub const ERROR_MESSAGE = 'BAD PUSH'; /** - * @param $prePush - * @param $rightMessage - * @param $errorMessage - * @param PhpUnitResponse $phpUnitResponse + * @param bool $prePush + * @param string $rightMessage + * @param string $errorMessage + * @param bool $enableFaces + * @param PhpUnitResponse $phpUnitResponse * @param PhpUnitStrictCoverageResponse $phpUnitStrictCoverageResponse - * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverageResponse + * @param PhpUnitGuardCoverageResponse $phpUnitGuardCoverageResponse * * @return PrePushResponse */ @@ -26,6 +27,7 @@ public static function create( $prePush, $rightMessage, $errorMessage, + $enableFaces, PhpUnitResponse $phpUnitResponse, PhpUnitStrictCoverageResponse $phpUnitStrictCoverageResponse, PhpUnitGuardCoverageResponse $phpUnitGuardCoverageResponse @@ -34,6 +36,7 @@ public static function create( $prePush, $rightMessage, $errorMessage, + $enableFaces, $phpUnitResponse, $phpUnitStrictCoverageResponse, $phpUnitGuardCoverageResponse @@ -49,6 +52,7 @@ public static function createAllEnabled() true, self::RIGHT_MESSAGE, self::ERROR_MESSAGE, + true, PhpUnitResponseStub::createEnabled(), PhpUnitStrictCoverageResponseStub::createEnabled(), PhpUnitGuardCoverageResponseStub::createEnabled() diff --git a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushStub.php b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushStub.php index e3b01ec..0979316 100644 --- a/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushStub.php +++ b/src/PhpGitHooks/Module/Configuration/Tests/Stub/PrePushStub.php @@ -55,7 +55,11 @@ public static function createAllEnabled() new Undefined(false), EnabledStub::create(true), PrePushExecuteStub::createEnabled(), - MessagesStub::create(MessageStub::create('0k'), MessageStub::create('Faltal')) + MessagesStub::create( + MessageStub::create('0k'), + MessageStub::create('Faltal'), + EnabledStub::create(true) + ) ); } diff --git a/src/PhpGitHooks/Module/Git/Contract/Command/PreCommitToolHandler.php b/src/PhpGitHooks/Module/Git/Contract/Command/PreCommitToolHandler.php index 1d46a32..36206f2 100644 --- a/src/PhpGitHooks/Module/Git/Contract/Command/PreCommitToolHandler.php +++ b/src/PhpGitHooks/Module/Git/Contract/Command/PreCommitToolHandler.php @@ -84,9 +84,7 @@ private function execute() return; } - /** - * @var ConfigurationDataResponse - */ + /** @var ConfigurationDataResponse $configurationData */ $configurationData = $this->queryBus->handle(new ConfigurationDataFinder()); $preCommit = $configurationData->getPreCommit(); @@ -94,7 +92,9 @@ private function execute() $this->executeTools($preCommit, $committedFiles); } - $this->output->writeln(GoodJobLogoResponse::paint($preCommit->getRightMessage())); + $this->output->writeln( + GoodJobLogoResponse::paint($preCommit->getRightMessage(), $preCommit->isEnableFaces()) + ); } /** @@ -105,13 +105,21 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi { if (true === $preCommitResponse->isComposer()) { $this->commandBus->handle( - new ComposerTool($committedFiles, $preCommitResponse->getErrorMessage()) + new ComposerTool( + $committedFiles, + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() + ) ); } if (true === $preCommitResponse->isJsonLint()) { $this->commandBus->handle( - new JsonLintTool($committedFiles, $preCommitResponse->getErrorMessage()) + new JsonLintTool( + $committedFiles, + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() + ) ); } @@ -120,7 +128,11 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi if ($phpFiles) { if (true === $preCommitResponse->isPhpLint()) { $this->commandBus->handle( - new PhpLintTool($phpFiles, $preCommitResponse->getErrorMessage()) + new PhpLintTool( + $phpFiles, + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() + ) ); } @@ -132,6 +144,7 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi $phpFiles, $phpCsResponse->getPhpCsStandard(), $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces(), $phpCsResponse->getIgnore() ) ); @@ -148,7 +161,8 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi $phpCsFixerResponse->isPhpCsFixerPsr2(), $phpCsFixerResponse->isPhpCsFixerSymfony(), $phpCsFixerResponse->getPhpCsFixerOptions(), - $preCommitResponse->getErrorMessage() + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() ) ); } @@ -160,7 +174,8 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi new PhpMdTool( $phpFiles, $phpMdResponse->getPhpMdOptions(), - $preCommitResponse->getErrorMessage() + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() ) ); } @@ -172,7 +187,8 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi new PhpUnitTool( $phpunitResponse->isPhpunitRandomMode(), $phpunitResponse->getPhpunitOptions(), - $preCommitResponse->getErrorMessage() + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() ) ); @@ -182,7 +198,8 @@ private function executeTools(PreCommitResponse $preCommitResponse, array $commi $this->commandBus->handle( new StrictCoverage( $phpunitStrictCoverageResponse->getMinimum(), - $preCommitResponse->getErrorMessage() + $preCommitResponse->getErrorMessage(), + $preCommitResponse->isEnableFaces() ) ); } diff --git a/src/PhpGitHooks/Module/Git/Contract/Command/PrePushToolHandler.php b/src/PhpGitHooks/Module/Git/Contract/Command/PrePushToolHandler.php index 5c310f5..8438a57 100644 --- a/src/PhpGitHooks/Module/Git/Contract/Command/PrePushToolHandler.php +++ b/src/PhpGitHooks/Module/Git/Contract/Command/PrePushToolHandler.php @@ -71,7 +71,12 @@ private function execute($remote, $url) if (true === $prePushResponse->isPrePush()) { $this->output->writeln(self::PRE_PUSH_HOOK); - $this->executeOriginalHook($remote, $url, $prePushResponse->getErrorMessage()); + $this->executeOriginalHook( + $remote, + $url, + $prePushResponse->getErrorMessage(), + $prePushResponse->isEnableFaces() + ); $phpunitResponse = $prePushResponse->getPhpUnit(); @@ -80,7 +85,8 @@ private function execute($remote, $url) new PhpUnitTool( $phpunitResponse->isPhpunitRandomMode(), $phpunitResponse->getPhpunitOptions(), - $prePushResponse->getErrorMessage() + $prePushResponse->getErrorMessage(), + $prePushResponse->isEnableFaces() ) ); @@ -90,7 +96,8 @@ private function execute($remote, $url) $this->commandBus->handle( new StrictCoverage( $phpunitStrictCoverageResponse->getMinimum(), - $prePushResponse->getErrorMessage() + $prePushResponse->getErrorMessage(), + $prePushResponse->isEnableFaces() ) ); } @@ -104,7 +111,9 @@ private function execute($remote, $url) } } - $this->output->writeln(GoodJobLogoResponse::paint($prePushResponse->getRightMessage())); + $this->output->writeln( + GoodJobLogoResponse::paint($prePushResponse->getRightMessage(), $prePushResponse->isEnableFaces()) + ); } } @@ -112,15 +121,16 @@ private function execute($remote, $url) * @param string $remote * @param string $url * @param string $errorMessage + * @param bool $enableFaces * * @throws InvalidPushException */ - private function executeOriginalHook($remote, $url, $errorMessage) + private function executeOriginalHook($remote, $url, $errorMessage, $enableFaces) { $response = $this->prePushOriginalExecutor->execute($remote, $url); if (null != $response) { - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new InvalidPushException(); } @@ -128,6 +138,8 @@ private function executeOriginalHook($remote, $url, $errorMessage) /** * @param CommandInterface|PrePushTool $command + * + * @throws InvalidPushException */ public function handle(CommandInterface $command) { diff --git a/src/PhpGitHooks/Module/Git/Contract/Response/BadJobLogoResponse.php b/src/PhpGitHooks/Module/Git/Contract/Response/BadJobLogoResponse.php index 8fe1ac6..dc45e68 100644 --- a/src/PhpGitHooks/Module/Git/Contract/Response/BadJobLogoResponse.php +++ b/src/PhpGitHooks/Module/Git/Contract/Response/BadJobLogoResponse.php @@ -6,12 +6,13 @@ final class BadJobLogoResponse { /** * @param string $message + * @param bool $enableFace * * @return string */ - public static function paint($message) + public static function paint($message, $enableFace) { - return sprintf(" + $face = $enableFace ? " @@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@ @@@@@ @@@@@@@ @@ -27,7 +28,11 @@ public static function paint($message) @@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@ - \n - %s \n", $message); + \n" : ''; + + return sprintf( + "$face %s \n", + $message + ); } } diff --git a/src/PhpGitHooks/Module/Git/Contract/Response/GoodJobLogoResponse.php b/src/PhpGitHooks/Module/Git/Contract/Response/GoodJobLogoResponse.php index 2b99d0e..5884d04 100644 --- a/src/PhpGitHooks/Module/Git/Contract/Response/GoodJobLogoResponse.php +++ b/src/PhpGitHooks/Module/Git/Contract/Response/GoodJobLogoResponse.php @@ -6,12 +6,13 @@ final class GoodJobLogoResponse { /** * @param string $message + * @param bool $enableFace * * @return string */ - public static function paint($message) + public static function paint($message, $enableFace) { - return sprintf(" + $face = $enableFace ? " @@@@@@@@@@@@@@@ @@@@ @@@@@@@@@@@@@@@@@@@ @ @ @@@@@@@@@@@@@@@@@@@@@@@ @@ -28,7 +29,11 @@ public static function paint($message) @@ @ @@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@ - \n - %s ", $message); + \n" : ''; + + return sprintf( + "$face %s ", + $message + ); } } diff --git a/src/PhpGitHooks/Module/Git/Tests/Behaviour/PreCommitToolHandlerTest.php b/src/PhpGitHooks/Module/Git/Tests/Behaviour/PreCommitToolHandlerTest.php index e50d876..6737554 100644 --- a/src/PhpGitHooks/Module/Git/Tests/Behaviour/PreCommitToolHandlerTest.php +++ b/src/PhpGitHooks/Module/Git/Tests/Behaviour/PreCommitToolHandlerTest.php @@ -65,23 +65,36 @@ public function itShouldExecuteAllTools() $this->shouldGetFilesCommitted($files); $this->shouldHandleQuery(new ConfigurationDataFinder(), $configurationDataResponse); $this->shouldHandleCommand( - new ComposerTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) + new ComposerTool( + $files, + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() + ) ); $this->shouldHandleCommand( - new JsonLintTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) + new JsonLintTool( + $files, + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() + ) ); $this->shouldHandleQuery( new PhpFilesExtractor($files), PhpFilesResponseStub::create(FilesCommittedStub::createWithoutPhpFiles()) ); $this->shouldHandleCommand( - new PhpLintTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) + new PhpLintTool( + $files, + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() + ) ); $this->shouldHandleCommand( new PhpCsTool( $files, $configurationDataResponse->getPreCommit()->getPhpCs()->getPhpCsStandard(), HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, + $configurationDataResponse->getPreCommit()->isEnableFaces(), $configurationDataResponse->getPreCommit()->getPhpCs()->getIgnore() ) ); @@ -93,28 +106,32 @@ public function itShouldExecuteAllTools() $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $configurationDataResponse->getPreCommit()->getPhpCsFixer()->getPhpCsFixerOptions(), - $configurationDataResponse->getPreCommit()->getErrorMessage() + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() ) ); $this->shouldHandleCommand( new PhpMdTool( $files, $configurationDataResponse->getPreCommit()->getPhpMd()->getPhpMdOptions(), - $configurationDataResponse->getPreCommit()->getErrorMessage() + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() ) ); $this->shouldHandleCommand( new PhpUnitTool( $configurationDataResponse->getPreCommit()->getPhpUnit()->isPhpunitRandomMode(), $configurationDataResponse->getPreCommit()->getPhpUnit()->getPhpunitOptions(), - $configurationDataResponse->getPreCommit()->getErrorMessage() + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() ) ); $this->shouldHandleCommand( new StrictCoverage( $configurationDataResponse->getPreCommit()->getPhpUnitStrictCoverage()->getMinimum(), - $configurationDataResponse->getPreCommit()->getErrorMessage() + $configurationDataResponse->getPreCommit()->getErrorMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() ) ); @@ -125,7 +142,10 @@ public function itShouldExecuteAllTools() ); $this->shouldWriteLnOutput( - GoodJobLogoResponse::paint($configurationDataResponse->getPreCommit()->getRightMessage()) + GoodJobLogoResponse::paint( + $configurationDataResponse->getPreCommit()->getRightMessage(), + $configurationDataResponse->getPreCommit()->isEnableFaces() + ) ); $this->preCommitToolCommandHandler->handle(new PreCommitTool()); diff --git a/src/PhpGitHooks/Module/Git/Tests/Behaviour/PrePushToolHandlerTest.php b/src/PhpGitHooks/Module/Git/Tests/Behaviour/PrePushToolHandlerTest.php index 2adfabe..c15bf75 100644 --- a/src/PhpGitHooks/Module/Git/Tests/Behaviour/PrePushToolHandlerTest.php +++ b/src/PhpGitHooks/Module/Git/Tests/Behaviour/PrePushToolHandlerTest.php @@ -35,6 +35,7 @@ protected function setUp() /** * @test + * @throws InvalidPushException */ public function itShouldNotExecuteHook() { @@ -48,6 +49,7 @@ public function itShouldNotExecuteHook() /** * @test + * @throws InvalidPushException */ public function itShouldThrowsExceptionFromOriginalScript() { @@ -62,7 +64,10 @@ public function itShouldThrowsExceptionFromOriginalScript() $this->shouldWriteLnOutput(PrePushToolHandler::PRE_PUSH_HOOK); $this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error'); $this->shouldWriteLnOutput( - BadJobLogoResponse::paint($configurationDataResponse->getPrePush()->getErrorMessage()) + BadJobLogoResponse::paint( + $configurationDataResponse->getPrePush()->getErrorMessage(), + $configurationDataResponse->getPrePush()->isEnableFaces() + ) ); $this->prePushToolCommandHandler->handle(new PrePushTool($this->remote, $this->url)); @@ -70,6 +75,7 @@ public function itShouldThrowsExceptionFromOriginalScript() /** * @test + * @throws InvalidPushException */ public function itShouldWorksFine() { @@ -85,13 +91,15 @@ public function itShouldWorksFine() new PhpUnitTool( $configurationDataResponse->getPrePush()->getPhpUnit()->isPhpunitRandomMode(), $configurationDataResponse->getPrePush()->getPhpUnit()->getPhpunitOptions(), - $configurationDataResponse->getPrePush()->getErrorMessage() + $configurationDataResponse->getPrePush()->getErrorMessage(), + $configurationDataResponse->getPrePush()->isEnableFaces() ) ); $this->shouldHandleCommand( new StrictCoverage( $configurationDataResponse->getPrePush()->getPhpUnitStrictCoverage()->getMinimum(), - $configurationDataResponse->getPrePush()->getErrorMessage() + $configurationDataResponse->getPrePush()->getErrorMessage(), + $configurationDataResponse->getPrePush()->isEnableFaces() ) ); @@ -102,7 +110,10 @@ public function itShouldWorksFine() ); $this->shouldWriteLnOutput( - GoodJobLogoResponse::paint($configurationDataResponse->getPrePush()->getRightMessage()) + GoodJobLogoResponse::paint( + $configurationDataResponse->getPrePush()->getRightMessage(), + $configurationDataResponse->getPrePush()->isEnableFaces() + ) ); $this->prePushToolCommandHandler->handle(new PrePushTool($this->remote, $this->url)); diff --git a/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintTool.php b/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintTool.php index a24a88b..b6ea28c 100644 --- a/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintTool.php +++ b/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintTool.php @@ -14,17 +14,23 @@ class JsonLintTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * JsonLintToolCommand constructor. * - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct(array $files, $errorMessage) + public function __construct(array $files, $errorMessage, $enableFaces) { $this->files = $files; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -35,6 +41,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return array */ diff --git a/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintToolHandler.php b/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintToolHandler.php index 5a788c1..f29e198 100644 --- a/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintToolHandler.php +++ b/src/PhpGitHooks/Module/JsonLint/Contract/Command/JsonLintToolHandler.php @@ -6,6 +6,7 @@ use Bruli\EventBusBundle\CommandBus\CommandInterface; use Bruli\EventBusBundle\QueryBus\QueryBus; use PhpGitHooks\Module\Files\Contract\Query\JsonFilesExtractor; +use PhpGitHooks\Module\JsonLint\Contract\Exception\JsonLintViolationsException; use PhpGitHooks\Module\JsonLint\Service\JsonLintToolExecutor; class JsonLintToolHandler implements CommandHandlerInterface @@ -34,15 +35,18 @@ public function __construct( } /** - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces + * + * @throws JsonLintViolationsException */ - private function execute(array $files, $errorMessage) + private function execute(array $files, $errorMessage, $enableFaces) { $jsonFilesResponse = $this->queryBus->handle(new JsonFilesExtractor($files)); if (true === $this->jsonFilesExists($jsonFilesResponse->getFiles())) { - $this->jsonLintToolExecutor->execute($jsonFilesResponse->getFiles(), $errorMessage); + $this->jsonLintToolExecutor->execute($jsonFilesResponse->getFiles(), $errorMessage, $enableFaces); } } @@ -58,9 +62,11 @@ private function jsonFilesExists(array $files) /** * @param CommandInterface|JsonLintTool $command + * + * @throws JsonLintViolationsException */ public function handle(CommandInterface $command) { - $this->execute($command->getFiles(), $command->getErrorMessage()); + $this->execute($command->getFiles(), $command->getErrorMessage(), $command->isEnableFaces()); } } diff --git a/src/PhpGitHooks/Module/JsonLint/Infrastructure/Tool/JsonLintProcessor.php b/src/PhpGitHooks/Module/JsonLint/Infrastructure/Tool/JsonLintProcessor.php index 539ee60..f0603dc 100644 --- a/src/PhpGitHooks/Module/JsonLint/Infrastructure/Tool/JsonLintProcessor.php +++ b/src/PhpGitHooks/Module/JsonLint/Infrastructure/Tool/JsonLintProcessor.php @@ -65,5 +65,7 @@ private function setErrors(Process $process) if (false === $process->isSuccessful()) { return $process->getErrorOutput(); } + + return null; } } diff --git a/src/PhpGitHooks/Module/JsonLint/Service/JsonLintToolExecutor.php b/src/PhpGitHooks/Module/JsonLint/Service/JsonLintToolExecutor.php index 7826cf2..db01776 100644 --- a/src/PhpGitHooks/Module/JsonLint/Service/JsonLintToolExecutor.php +++ b/src/PhpGitHooks/Module/JsonLint/Service/JsonLintToolExecutor.php @@ -33,12 +33,13 @@ public function __construct(JsonLintProcessorInterface $jsonLintProcessor, Outpu } /** - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces * * @throws JsonLintViolationsException */ - public function execute(array $files, $errorMessage) + public function execute(array $files, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE); $this->output->write($outputMessage->getMessage()); @@ -53,7 +54,7 @@ public function execute(array $files, $errorMessage) if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputMessage->setError(implode('', $errors))); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new JsonLintViolationsException(implode('', $errors)); } diff --git a/src/PhpGitHooks/Module/JsonLint/Tests/Behaviour/JsonLintToolHandlerTest.php b/src/PhpGitHooks/Module/JsonLint/Tests/Behaviour/JsonLintToolHandlerTest.php index 3eea0d9..4428415 100644 --- a/src/PhpGitHooks/Module/JsonLint/Tests/Behaviour/JsonLintToolHandlerTest.php +++ b/src/PhpGitHooks/Module/JsonLint/Tests/Behaviour/JsonLintToolHandlerTest.php @@ -40,6 +40,7 @@ protected function setUp() /** * @test + * @throws JsonLintViolationsException */ public function itShouldNotExecuteTool() { @@ -51,12 +52,13 @@ public function itShouldNotExecuteTool() ); $this->jsonLintToolCommandHandler->handle( - new JsonLintTool($files, $this->errorMessage) + new JsonLintTool($files, $this->errorMessage, true) ); } /** * @test + * @throws JsonLintViolationsException */ public function itShouldExecuteTool() { @@ -76,12 +78,13 @@ public function itShouldExecuteTool() $this->shouldWriteLnOutput($output->getSuccessfulMessage()); $this->jsonLintToolCommandHandler->handle( - new JsonLintTool($files->getFiles(), $this->errorMessage) + new JsonLintTool($files->getFiles(), $this->errorMessage, true) ); } /** * @test + * @throws JsonLintViolationsException */ public function itShouldThrowsException() { @@ -105,10 +108,10 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($output->getFailMessage()); $this->shouldWriteLnOutput($output->setError($errorTxt)); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage, true)); $this->jsonLintToolCommandHandler->handle( - new JsonLintTool($jsonFilesResponse->getFiles(), $this->errorMessage) + new JsonLintTool($jsonFilesResponse->getFiles(), $this->errorMessage, true) ); } } diff --git a/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsTool.php b/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsTool.php index 996c844..21f9942 100644 --- a/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsTool.php +++ b/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsTool.php @@ -18,6 +18,10 @@ class PhpCsTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var string + */ + private $enableFaces; /** * @var string */ @@ -26,16 +30,18 @@ class PhpCsTool implements CommandInterface /** * PhpCsToolCommand constructor. * - * @param array $files + * @param array $files * @param string $standard * @param string $errorMessage + * @param bool $enableFaces * @param string $ignore */ - public function __construct(array $files, $standard, $errorMessage, $ignore) + public function __construct(array $files, $standard, $errorMessage, $enableFaces, $ignore) { $this->files = $files; $this->standard = $standard; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; $this->ignore = $ignore; } @@ -47,6 +53,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return string + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return array */ diff --git a/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsToolHandler.php b/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsToolHandler.php index 965c8cc..88cf303 100644 --- a/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsToolHandler.php +++ b/src/PhpGitHooks/Module/PhpCs/Contract/Command/PhpCsToolHandler.php @@ -38,11 +38,12 @@ public function __construct(OutputInterface $output, PhpCsToolProcessorInterface * @param array $files * @param string $standard * @param string $errorMessage + * @param bool $enableFace * @param string $ignore * * @throws PhpCsViolationException */ - private function execute(array $files, $standard, $errorMessage, $ignore) + private function execute(array $files, $standard, $errorMessage, $enableFace, $ignore) { $outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE); $this->output->write($outputMessage->getMessage()); @@ -57,7 +58,7 @@ private function execute(array $files, $standard, $errorMessage, $ignore) if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputMessage->setError(implode('', $errors))); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFace)); throw new PhpCsViolationException(); } $this->output->writeln($outputMessage->getSuccessfulMessage()); @@ -73,6 +74,7 @@ public function handle(CommandInterface $command) $command->getFiles(), $command->getStandard(), $command->getErrorMessage(), + $command->isEnableFaces(), $command->getIgnore() ); } diff --git a/src/PhpGitHooks/Module/PhpCs/Tests/Behaviour/PhpCsToolHandlerTest.php b/src/PhpGitHooks/Module/PhpCs/Tests/Behaviour/PhpCsToolHandlerTest.php index 7eb4e5b..73d4ef8 100644 --- a/src/PhpGitHooks/Module/PhpCs/Tests/Behaviour/PhpCsToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpCs/Tests/Behaviour/PhpCsToolHandlerTest.php @@ -28,6 +28,7 @@ protected function setUp() /** * @test + * @throws PhpCsViolationException */ public function itShouldThrowsException() { @@ -47,13 +48,16 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($output->getFailMessage()); $this->shouldWriteLnOutput($output->setError($errorTxt)); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint(HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)); + $this->shouldWriteLnOutput( + BadJobLogoResponse::paint(HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, true) + ); $this->phpCsToolCommandHandler->handle( new PhpCsTool( $files, 'PSR2', HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, + true, '' ) ); @@ -61,6 +65,7 @@ public function itShouldThrowsException() /** * @test + * @throws PhpCsViolationException */ public function itShouldWorksFine() { @@ -80,6 +85,7 @@ public function itShouldWorksFine() $files, 'PSR2', HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, + true, '' ) ); diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerTool.php b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerTool.php index 5a7112d..62cc7cc 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerTool.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerTool.php @@ -34,19 +34,24 @@ class PhpCsFixerTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * PhpCsFixerToolCommand constructor. * - * @param array $files - * @param bool $psr0 - * @param bool $psr1 - * @param bool $psr2 - * @param bool $symfony + * @param array $files + * @param bool $psr0 + * @param bool $psr1 + * @param bool $psr2 + * @param bool $symfony * @param string $options * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage) + public function __construct(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage, $enableFaces) { $this->files = $files; $this->psr0 = $psr0; @@ -55,6 +60,7 @@ public function __construct(array $files, $psr0, $psr1, $psr2, $symfony, $option $this->symfony = $symfony; $this->options = $options; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -112,4 +118,12 @@ public function getErrorMessage() { return $this->errorMessage; } + + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } } diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php index 8dd53e7..3f20393 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Contract/Command/PhpCsFixerToolHandler.php @@ -41,23 +41,26 @@ public function __construct(OutputInterface $output, PhpCsFixerToolProcessorInte * @param bool $symfony * @param string $options * @param string $errorMessage + * @param bool $enableFaces + * + * @throws PhpCsFixerViolationsException */ - private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage) + private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage, $enableFaces) { if (true === $psr0) { - $this->executeTool($files, '@PSR0', $options, $errorMessage); + $this->executeTool($files, '@PSR0', $options, $errorMessage, $enableFaces); } if (true === $psr1) { - $this->executeTool($files, '@PSR1', $options, $errorMessage); + $this->executeTool($files, '@PSR1', $options, $errorMessage, $enableFaces); } if (true === $psr2) { - $this->executeTool($files, '@PSR2', $options, $errorMessage); + $this->executeTool($files, '@PSR2', $options, $errorMessage, $enableFaces); } if (true === $symfony) { - $this->executeTool($files, '@Symfony', $options, $errorMessage); + $this->executeTool($files, '@Symfony', $options, $errorMessage, $enableFaces); } } @@ -66,10 +69,11 @@ private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, * @param string $level * @param string $options * @param string $errorMessage + * @param bool $enableFaces * * @throws PhpCsFixerViolationsException */ - private function executeTool(array $files, $level, $options, $errorMessage) + private function executeTool(array $files, $level, $options, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter( sprintf('Checking %s code style with PHP-CS-FIXER', str_replace('@', '', $level)) @@ -87,7 +91,7 @@ private function executeTool(array $files, $level, $options, $errorMessage) $this->output->writeln($outputMessage->getFailMessage()); $errorsText = $outputMessage->setError(implode('', $errors)); $this->output->writeln($errorsText); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new PhpCsFixerViolationsException(); } @@ -96,6 +100,8 @@ private function executeTool(array $files, $level, $options, $errorMessage) /** * @param CommandInterface|PhpCsFixerTool $command + * + * @throws PhpCsFixerViolationsException */ public function handle(CommandInterface $command) { @@ -106,7 +112,8 @@ public function handle(CommandInterface $command) $command->isPsr2(), $command->isSymfony(), $command->getOptions(), - $command->getErrorMessage() + $command->getErrorMessage(), + $command->isEnableFaces() ); } } diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php index 2a50578..d594026 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Infrastructure/Tool/PhpCsFixerToolProcessor.php @@ -76,5 +76,7 @@ private function setError(Process $process) if (false === $process->isSuccessful()) { return $process->getErrorOutput(); } + + return null; } } diff --git a/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php b/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php index ff8ea5b..1248200 100644 --- a/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpCsFixer/Tests/Behaviour/PhpCsFixerToolHandlerTest.php @@ -50,7 +50,12 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errors)); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($configurationData->getPreCommit()->getErrorMessage())); + $this->shouldWriteLnOutput( + BadJobLogoResponse::paint( + $configurationData->getPreCommit()->getErrorMessage(), + $configurationData->getPreCommit()->isEnableFaces() + ) + ); $this->phpCsFixerToolCommandHandler->handle( new PhpCsFixerTool( @@ -60,7 +65,8 @@ public function itShouldThrowsException() $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $phpCsFixerOptions->value(), - $configurationData->getPreCommit()->getErrorMessage() + $configurationData->getPreCommit()->getErrorMessage(), + $configurationData->getPreCommit()->isEnableFaces() ) ); } @@ -118,7 +124,8 @@ public function itShouldWorksFine() $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), $configurationData->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), $phpCsFixerOptions->value(), - $configurationData->getPreCommit()->getErrorMessage() + $configurationData->getPreCommit()->getErrorMessage(), + $configurationData->getPreCommit()->isEnableFaces() ) ); } diff --git a/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintTool.php b/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintTool.php index 3734947..6b31842 100644 --- a/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintTool.php +++ b/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintTool.php @@ -14,17 +14,23 @@ class PhpLintTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * PhpLintToolCommand constructor. * - * @param array $files + * @param array $files * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct(array $files, $errorMessage) + public function __construct(array $files, $errorMessage, $enableFaces) { $this->files = $files; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -42,4 +48,12 @@ public function getErrorMessage() { return $this->errorMessage; } + + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } } diff --git a/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintToolHandler.php b/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintToolHandler.php index 95fe23c..1facb4e 100644 --- a/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintToolHandler.php +++ b/src/PhpGitHooks/Module/PhpLint/Contract/Command/PhpLintToolHandler.php @@ -37,10 +37,11 @@ public function __construct(PhpLintToolProcessorInterface $phpLintTool, OutputIn /** * @param array $files * @param string $errorMessage + * @param bool $enableFaces * * @throws PhpLintViolationsException */ - private function execute(array $files, $errorMessage) + private function execute(array $files, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter(self::RUNNING_PHPLINT); $this->output->write($outputMessage->getMessage()); @@ -55,7 +56,7 @@ private function execute(array $files, $errorMessage) if (!empty($errors)) { $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputMessage->setError(implode('', $errors))); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new PhpLintViolationsException(); } @@ -65,9 +66,11 @@ private function execute(array $files, $errorMessage) /** * @param CommandInterface|PhpLintTool $command + * + * @throws PhpLintViolationsException */ public function handle(CommandInterface $command) { - $this->execute($command->getFiles(), $command->getErrorMessage()); + $this->execute($command->getFiles(), $command->getErrorMessage(), $command->isEnableFaces()); } } diff --git a/src/PhpGitHooks/Module/PhpLint/Tests/Behaviour/PhpLintToolHandlerTest.php b/src/PhpGitHooks/Module/PhpLint/Tests/Behaviour/PhpLintToolHandlerTest.php index d6c89d1..6d807ee 100644 --- a/src/PhpGitHooks/Module/PhpLint/Tests/Behaviour/PhpLintToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpLint/Tests/Behaviour/PhpLintToolHandlerTest.php @@ -29,6 +29,7 @@ protected function setUp() /** * @test + * @throws PhpLintViolationsException */ public function itShouldThrowsException() { @@ -49,15 +50,16 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errors)); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage, true)); $this->phpLintToolCommandHandler->handle( - new PhpLintTool($phpFiles, $errorMessage) + new PhpLintTool($phpFiles, $errorMessage, true) ); } /** * @test + * @throws PhpLintViolationsException */ public function itShouldWorksFine() { @@ -73,7 +75,7 @@ public function itShouldWorksFine() $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage()); $this->phpLintToolCommandHandler->handle( - new PhpLintTool($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT) + new PhpLintTool($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, true) ); } } diff --git a/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdTool.php b/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdTool.php index 2b8c353..8141d6a 100644 --- a/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdTool.php +++ b/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdTool.php @@ -14,6 +14,10 @@ class PhpMdTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * @var string */ @@ -22,14 +26,16 @@ class PhpMdTool implements CommandInterface /** * PhpMdToolCommand constructor. * - * @param array $files + * @param array $files * @param string $options * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct(array $files, $options, $errorMessage) + public function __construct(array $files, $options, $errorMessage, $enableFaces) { $this->files = $files; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; $this->options = $options; } @@ -49,6 +55,14 @@ public function getErrorMessage() return $this->errorMessage; } + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } + /** * @return string */ diff --git a/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdToolHandler.php b/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdToolHandler.php index eaf2476..880c9dc 100644 --- a/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdToolHandler.php +++ b/src/PhpGitHooks/Module/PhpMd/Contract/Command/PhpMdToolHandler.php @@ -35,13 +35,14 @@ public function __construct(OutputInterface $output, PhpMdToolProcessorInterface } /** - * @param array $files + * @param array $files * @param string $options * @param string $errorMessage + * @param bool $enableFaces * * @throws PhpMdViolationsException */ - private function execute(array $files, $options, $errorMessage) + private function execute(array $files, $options, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE); $this->output->write($outputMessage->getMessage()); @@ -57,7 +58,7 @@ private function execute(array $files, $options, $errorMessage) $outputText = $outputMessage->setError(implode('', $errors)); $this->output->writeln($outputMessage->getFailMessage()); $this->output->writeln($outputText); - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new PhpMdViolationsException(); } @@ -66,9 +67,16 @@ private function execute(array $files, $options, $errorMessage) /** * @param CommandInterface|PhpMdTool $command + * + * @throws PhpMdViolationsException */ public function handle(CommandInterface $command) { - $this->execute($command->getFiles(), $command->getOptions(), $command->getErrorMessage()); + $this->execute( + $command->getFiles(), + $command->getOptions(), + $command->getErrorMessage(), + $command->isEnableFaces() + ); } } diff --git a/src/PhpGitHooks/Module/PhpMd/Tests/Behaviour/PhpMdToolHandlerTest.php b/src/PhpGitHooks/Module/PhpMd/Tests/Behaviour/PhpMdToolHandlerTest.php index 394d12b..e37695d 100644 --- a/src/PhpGitHooks/Module/PhpMd/Tests/Behaviour/PhpMdToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpMd/Tests/Behaviour/PhpMdToolHandlerTest.php @@ -29,6 +29,7 @@ protected function setUp() /** * @test + * @throws PhpMdViolationsException */ public function itShouldThrowsException() { @@ -50,14 +51,15 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($outputMessage->getFailMessage()); $this->shouldWriteLnOutput($outputMessage->setError($errorsText)); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage, true)); - $command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage); + $command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage, true); $this->phpMdToolCommandHandler->handle($command); } /** * @test + * @throws PhpMdViolationsException */ public function itShouldWorksFine() { @@ -74,7 +76,7 @@ public function itShouldWorksFine() $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage()); - $command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage); + $command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage, true); $this->phpMdToolCommandHandler->handle($command); } } diff --git a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitTool.php b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitTool.php index 596af3d..39d26e5 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitTool.php +++ b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitTool.php @@ -18,19 +18,25 @@ class PhpUnitTool implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * PhpUnitToolCommand constructor. * - * @param bool $randomMode + * @param bool $randomMode * @param string|null $options - * @param string $errorMessage + * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct($randomMode, $options, $errorMessage) + public function __construct($randomMode, $options, $errorMessage, $enableFaces) { $this->randomMode = $randomMode; $this->options = $options; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -56,4 +62,12 @@ public function getErrorMessage() { return $this->errorMessage; } + + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } } diff --git a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitToolHandler.php b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitToolHandler.php index 4d141af..ef2f940 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitToolHandler.php +++ b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/PhpUnitToolHandler.php @@ -6,7 +6,6 @@ use Bruli\EventBusBundle\CommandBus\CommandInterface; use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; -use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool; use PhpGitHooks\Module\PhpUnit\Contract\Exception\PhpUnitViolationException; use PhpGitHooks\Module\PhpUnit\Model\PhpUnitProcessorInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -48,10 +47,11 @@ public function __construct( * @param string $randomMode * @param string $options * @param string $errorMessage + * @param bool $enableFaces * * @throws PhpUnitViolationException */ - private function execute($randomMode, $options, $errorMessage) + private function execute($randomMode, $options, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter(self::EXECUTING_MESSAGE); $this->output->writeln($outputMessage->getMessage()); @@ -59,7 +59,7 @@ private function execute($randomMode, $options, $errorMessage) $testResult = $this->executeTool($randomMode, $options); if (false === $testResult) { - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new PhpUnitViolationException(); } @@ -80,13 +80,16 @@ protected function executeTool($randomMode, $options) /** * @param CommandInterface|PhpUnitTool $command + * + * @throws PhpUnitViolationException */ public function handle(CommandInterface $command) { $this->execute( $command->isRandomMode(), $command->getOptions(), - $command->getErrorMessage() + $command->getErrorMessage(), + $command->isEnableFaces() ); } } diff --git a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverage.php b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverage.php index 1600c39..d70813b 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverage.php +++ b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverage.php @@ -14,17 +14,23 @@ class StrictCoverage implements CommandInterface * @var string */ private $errorMessage; + /** + * @var bool + */ + private $enableFaces; /** * StrictCoverageCommand constructor. * - * @param float $minimumCoverage + * @param float $minimumCoverage * @param string $errorMessage + * @param bool $enableFaces */ - public function __construct($minimumCoverage, $errorMessage) + public function __construct($minimumCoverage, $errorMessage, $enableFaces) { $this->minimumCoverage = $minimumCoverage; $this->errorMessage = $errorMessage; + $this->enableFaces = $enableFaces; } /** @@ -42,4 +48,12 @@ public function getErrorMessage() { return $this->errorMessage; } + + /** + * @return bool + */ + public function isEnableFaces() + { + return $this->enableFaces; + } } diff --git a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverageToolHandler.php b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverageToolHandler.php index b0312f3..1bd8ee9 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverageToolHandler.php +++ b/src/PhpGitHooks/Module/PhpUnit/Contract/Command/StrictCoverageToolHandler.php @@ -6,6 +6,7 @@ use Bruli\EventBusBundle\CommandBus\CommandInterface; use PhpGitHooks\Module\Configuration\Domain\MinimumStrictCoverage; use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; +use PhpGitHooks\Module\PhpUnit\Contract\Exception\InvalidStrictCoverageException; use PhpGitHooks\Module\PhpUnit\Service\StrictCoverageTool; use Symfony\Component\Console\Output\OutputInterface; @@ -35,12 +36,15 @@ public function __construct(OutputInterface $output, StrictCoverageTool $strictC /** * @param MinimumStrictCoverage $minimumStrictCoverage * @param string $errorMessage + * @param bool $enableFaces + * + * @throws InvalidStrictCoverageException */ - private function execute(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage) + private function execute(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage, $enableFaces) { $outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE); $this->output->write($outputMessage->getMessage()); - $currentCoverage = $this->strictCoverageTool->run($minimumStrictCoverage, $errorMessage); + $currentCoverage = $this->strictCoverageTool->run($minimumStrictCoverage, $errorMessage, $enableFaces); $this->output->writeln($outputMessage->getSuccessfulMessage() . $this->printCurrentCoverage($currentCoverage)); } @@ -55,12 +59,15 @@ private function printCurrentCoverage($currentCoverage) /** * @param CommandInterface|StrictCoverage $command + * + * @throws InvalidStrictCoverageException */ public function handle(CommandInterface $command) { $this->execute( new MinimumStrictCoverage($command->getMinimumCoverage()), - $command->getErrorMessage() + $command->getErrorMessage(), + $command->isEnableFaces() ); } } diff --git a/src/PhpGitHooks/Module/PhpUnit/Service/StrictCoverageTool.php b/src/PhpGitHooks/Module/PhpUnit/Service/StrictCoverageTool.php index 8ff5f22..a80e999 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Service/StrictCoverageTool.php +++ b/src/PhpGitHooks/Module/PhpUnit/Service/StrictCoverageTool.php @@ -34,16 +34,17 @@ public function __construct(StrictCoverageProcessorInterface $strictCoverageProc /** * @param MinimumStrictCoverage $minimumStrictCoverage * @param string $errorMessage + * @param bool $enableFaces * * @return float * @throws InvalidStrictCoverageException */ - public function run(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage) + public function run(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage, $enableFaces) { $currentCoverage = $this->strictCoverageProcessor->process(); if ($minimumStrictCoverage->value() > $currentCoverage) { - $this->output->writeln(BadJobLogoResponse::paint($errorMessage)); + $this->output->writeln(BadJobLogoResponse::paint($errorMessage, $enableFaces)); throw new InvalidStrictCoverageException($currentCoverage, $minimumStrictCoverage->value()); } diff --git a/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/PhpUnitToolHandlerTest.php b/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/PhpUnitToolHandlerTest.php index 89073d0..864f4ad 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/PhpUnitToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/PhpUnitToolHandlerTest.php @@ -28,6 +28,7 @@ protected function setUp() /** * @test + * @throws PhpUnitViolationException */ public function itShouldThrowsException() { @@ -39,19 +40,21 @@ public function itShouldThrowsException() $this->shouldWriteLnOutput($outputMessage->getMessage()); $this->shouldProcessPhpUnit($options, false); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage, true)); $this->phpUnitToolCommandHandler->handle( new PhpUnitTool( true, $options, - $errorMessage + $errorMessage, + true ) ); } /** * @test + * @throws PhpUnitViolationException */ public function itShouldExecuteAndWorksFine() { @@ -66,7 +69,8 @@ public function itShouldExecuteAndWorksFine() new PhpUnitTool( true, $options, - $errorMessage + $errorMessage, + true ) ); } diff --git a/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/StrictCoverageToolHandlerTest.php b/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/StrictCoverageToolHandlerTest.php index 7f7f9ab..103b9d4 100644 --- a/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/StrictCoverageToolHandlerTest.php +++ b/src/PhpGitHooks/Module/PhpUnit/Tests/Behaviour/StrictCoverageToolHandlerTest.php @@ -37,6 +37,7 @@ protected function setUp() /** * @test + * @throws InvalidStrictCoverageException */ public function itShouldThrowsException() { @@ -47,14 +48,15 @@ public function itShouldThrowsException() $this->shouldWriteOutput($outputMessage->getMessage()); $this->shouldProcessStrictCoverage(0.00); - $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); + $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage, true)); - $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage); + $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage, true); $this->strictCoverageToolCommandHandler->handle($command); } /** * @test + * @throws InvalidStrictCoverageException */ public function itShouldWorksFine() { @@ -72,7 +74,7 @@ public function itShouldWorksFine() ) ); - $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage); + $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage, true); $this->strictCoverageToolCommandHandler->handle($command); }