1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Git\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinder; |
7
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
8
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub; |
9
|
|
|
use PhpGitHooks\Module\Files\Contract\Query\PhpFilesExtractor; |
10
|
|
|
use PhpGitHooks\Module\Files\Tests\Stub\PhpFilesResponseStub; |
11
|
|
|
use PhpGitHooks\Module\Git\Contract\Command\PreCommitTool; |
12
|
|
|
use PhpGitHooks\Module\Git\Contract\Command\PreCommitToolHandler; |
13
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse; |
14
|
|
|
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase; |
15
|
|
|
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub; |
16
|
|
|
use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintToolCommand; |
17
|
|
|
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsToolCommand; |
18
|
|
|
use PhpGitHooks\Module\PhpCsFixer\Contract\Command\PhpCsFixerToolCommand; |
19
|
|
|
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintToolCommand; |
20
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdToolCommand; |
21
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand; |
22
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolCommand; |
23
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageCommand; |
24
|
|
|
use PhpGitHooks\Module\Tests\Infrastructure\Stub\StubCreator; |
25
|
|
|
|
26
|
|
|
class PreCommitToolHandlerTest extends GitUnitTestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var PreCommitToolHandler |
30
|
|
|
*/ |
31
|
|
|
private $preCommitToolCommandHandler; |
32
|
|
|
|
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->preCommitToolCommandHandler = new PreCommitToolHandler( |
36
|
|
|
$this->getOutputInterface(), |
37
|
|
|
$this->getFilesCommittedExtractor(), |
|
|
|
|
38
|
|
|
$this->getQueryBus(), |
|
|
|
|
39
|
|
|
$this->getCommandBus(), |
|
|
|
|
40
|
|
|
$this->getToolTitleOutputWriter() |
|
|
|
|
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function itShouldNotExecuteTools() |
48
|
|
|
{ |
49
|
|
|
$this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title'); |
50
|
|
|
$this->shouldGetFilesCommitted([StubCreator::faker()->sha1]); |
51
|
|
|
$this->shouldWriteLnOutput(PreCommitToolHandler::NO_FILES_CHANGED_MESSAGE); |
52
|
|
|
|
53
|
|
|
$this->preCommitToolCommandHandler->handle(new PreCommitTool()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
|
public function itShouldExecuteAllTools() |
60
|
|
|
{ |
61
|
|
|
$files = FilesCommittedStub::createAllFiles(); |
62
|
|
|
$configurationDataResponse = ConfigurationDataResponseStub::createAllEnabled(); |
63
|
|
|
|
64
|
|
|
$this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title'); |
65
|
|
|
$this->shouldGetFilesCommitted($files); |
66
|
|
|
$this->shouldHandleQuery(new ConfigurationDataFinder(), $configurationDataResponse); |
67
|
|
|
$this->shouldHandleCommand( |
68
|
|
|
new ComposerTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) |
69
|
|
|
); |
70
|
|
|
$this->shouldHandleCommand( |
71
|
|
|
new JsonLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) |
72
|
|
|
); |
73
|
|
|
$this->shouldHandleQuery( |
74
|
|
|
new PhpFilesExtractor($files), |
75
|
|
|
PhpFilesResponseStub::create(FilesCommittedStub::createWithoutPhpFiles()) |
76
|
|
|
); |
77
|
|
|
$this->shouldHandleCommand( |
78
|
|
|
new PhpLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage()) |
79
|
|
|
); |
80
|
|
|
$this->shouldHandleCommand( |
81
|
|
|
new PhpCsToolCommand( |
82
|
|
|
$files, |
83
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCs()->getPhpCsStandard(), |
84
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, |
85
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCs()->getIgnore() |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
$this->shouldHandleCommand( |
89
|
|
|
new PhpCsFixerToolCommand( |
90
|
|
|
$files, |
91
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(), |
92
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(), |
93
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(), |
94
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(), |
95
|
|
|
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->getPhpCsFixerOptions(), |
96
|
|
|
$configurationDataResponse->getPreCommit()->getErrorMessage() |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
$this->shouldHandleCommand( |
100
|
|
|
new PhpMdToolCommand( |
101
|
|
|
$files, |
102
|
|
|
$configurationDataResponse->getPreCommit()->getPhpMd()->getPhpMdOptions(), |
103
|
|
|
$configurationDataResponse->getPreCommit()->getErrorMessage() |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
$this->shouldHandleCommand( |
107
|
|
|
new PhpUnitToolCommand( |
108
|
|
|
$configurationDataResponse->getPreCommit()->getPhpUnit()->isPhpunitRandomMode(), |
109
|
|
|
$configurationDataResponse->getPreCommit()->getPhpUnit()->getPhpunitOptions(), |
110
|
|
|
$configurationDataResponse->getPreCommit()->getErrorMessage() |
111
|
|
|
) |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$this->shouldHandleCommand( |
115
|
|
|
new StrictCoverageCommand( |
116
|
|
|
$configurationDataResponse->getPreCommit()->getPhpUnitStrictCoverage()->getMinimum(), |
117
|
|
|
$configurationDataResponse->getPreCommit()->getErrorMessage() |
118
|
|
|
) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->shouldHandleCommand( |
122
|
|
|
new GuardCoverageCommand( |
123
|
|
|
$configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage() |
124
|
|
|
) |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$this->shouldWriteLnOutput( |
128
|
|
|
GoodJobLogoResponse::paint($configurationDataResponse->getPreCommit()->getRightMessage()) |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$this->preCommitToolCommandHandler->handle(new PreCommitTool()); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.