1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Configuration\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Contract\Command\ConfigurationProcessor; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Contract\Command\ConfigurationProcessorHandler; |
7
|
|
|
use PhpGitHooks\Module\Configuration\Service\CommitMsgProcessor; |
8
|
|
|
use PhpGitHooks\Module\Configuration\Service\ConfigurationArrayTransformer; |
9
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
10
|
|
|
use PhpGitHooks\Module\Configuration\Service\PhpGuardCoverageGitIgnoreConfigurator; |
11
|
|
|
use PhpGitHooks\Module\Configuration\Service\PhpUnitGuardCoverageConfigurator; |
12
|
|
|
use PhpGitHooks\Module\Configuration\Service\PreCommitProcessor; |
13
|
|
|
use PhpGitHooks\Module\Configuration\Service\PrePushProcessor; |
14
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Infrastructure\ConfigurationUnitTestCase; |
15
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\CommitMsgStub; |
16
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigArrayDataStub; |
17
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigStub; |
18
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitStub; |
19
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PrePushStub; |
20
|
|
|
use PhpGitHooks\Module\Git\Contract\Command\GitIgnoreWriterCommand; |
21
|
|
|
use PhpGitHooks\Module\Git\Contract\Query\GitIgnoreExtractorQuery; |
22
|
|
|
use PhpGitHooks\Module\Git\Tests\Stub\GitIgnoreDataResponseStub; |
23
|
|
|
|
24
|
|
|
final class ConfigurationProcessorHandlerTest extends ConfigurationUnitTestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ConfigurationProcessorHandler |
28
|
|
|
*/ |
29
|
|
|
private $configurationProcessorCommandHandler; |
30
|
|
|
|
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->configurationProcessorCommandHandler = new ConfigurationProcessorHandler( |
34
|
|
|
$this->getConfigurationFileReader(), |
|
|
|
|
35
|
|
|
new PreCommitProcessor( |
36
|
|
|
new PhpUnitGuardCoverageConfigurator( |
37
|
|
|
new PhpGuardCoverageGitIgnoreConfigurator( |
38
|
|
|
$this->getQueryBus(), |
|
|
|
|
39
|
|
|
$this->getCommandBus() |
|
|
|
|
40
|
|
|
) |
41
|
|
|
) |
42
|
|
|
), |
43
|
|
|
new CommitMsgProcessor(), |
44
|
|
|
$this->getConfigurationFileWriter(), |
|
|
|
|
45
|
|
|
$this->getHookCopier(), |
|
|
|
|
46
|
|
|
new PrePushProcessor( |
47
|
|
|
new PhpUnitGuardCoverageConfigurator( |
48
|
|
|
new PhpGuardCoverageGitIgnoreConfigurator( |
49
|
|
|
$this->getQueryBus(), |
|
|
|
|
50
|
|
|
$this->getCommandBus() |
|
|
|
|
51
|
|
|
) |
52
|
|
|
) |
53
|
|
|
) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @test |
59
|
|
|
*/ |
60
|
|
|
public function itShouldMakeAllQuestions() |
61
|
|
|
{ |
62
|
|
|
$yes = 'y'; |
63
|
|
|
$gitIgnoreDataResponse = GitIgnoreDataResponseStub::random(); |
64
|
|
|
|
65
|
|
|
$this->shouldReadConfigurationData(ConfigStub::createUndefined()); |
66
|
|
|
$this->shouldAsk(HookQuestions::PRE_COMMIT_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
67
|
|
|
$this->shouldAsk( |
68
|
|
|
HookQuestions::PRE_COMMIT_RIGHT_MESSAGE, |
69
|
|
|
HookQuestions::PRE_COMMIT_RIGHT_MESSAGE_DEFAULT, |
70
|
|
|
ConfigArrayDataStub::RIGHT_MESSAGE |
71
|
|
|
); |
72
|
|
|
$this->shouldAsk( |
73
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE, |
74
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, |
75
|
|
|
ConfigArrayDataStub::ERROR_MESSAGE |
76
|
|
|
); |
77
|
|
|
$this->shouldAsk(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
78
|
|
|
$this->shouldAsk(HookQuestions::JSONLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
79
|
|
|
$this->shouldAsk(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
80
|
|
|
$this->shouldAsk(HookQuestions::PHPMD_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
81
|
|
|
$this->shouldAsk(HookQuestions::PHPMD_OPTIONS, null, ConfigArrayDataStub::PHPMD_OPTIONS); |
82
|
|
|
$this->shouldAsk(HookQuestions::PHPCS_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
83
|
|
|
$this->shouldAsk(HookQuestions::PHPCS_STANDARD, null, ConfigArrayDataStub::PHPCS_STANDARD); |
84
|
|
|
$this->shouldAsk(HookQuestions::PHPCS_IGNORE, null, ConfigArrayDataStub::EMPTY_STRING); |
85
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
86
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR0_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
87
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR1_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
88
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR2_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
89
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_SYMFONY_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
90
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_OPTIONS, null, ConfigArrayDataStub::PHPCSFIXER_OPTIONS); |
91
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
92
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
93
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS); |
94
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
95
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE); |
96
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
97
|
|
|
$this->shouldAsk( |
98
|
|
|
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE, |
99
|
|
|
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT, |
100
|
|
|
ConfigArrayDataStub::ERROR_MESSAGE |
101
|
|
|
); |
102
|
|
|
$this->shouldHandleQuery(new GitIgnoreExtractorQuery(), $gitIgnoreDataResponse); |
103
|
|
|
$this->shouldHandleCommand(new GitIgnoreWriterCommand($gitIgnoreDataResponse->getContent())); |
104
|
|
|
|
105
|
|
|
$this->shouldAsk(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
106
|
|
|
$this->shouldCopyPreCommitHook(); |
107
|
|
|
$this->shouldAsk( |
108
|
|
|
HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION, |
109
|
|
|
HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER, |
110
|
|
|
ConfigArrayDataStub::REGULAR_EXPRESSION |
111
|
|
|
); |
112
|
|
|
$this->shouldCopyCommitMsgHook(); |
113
|
|
|
$this->shouldAsk(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
114
|
|
|
$this->shouldAsk( |
115
|
|
|
HookQuestions::PRE_PUSH_RIGHT_MESSAGE, |
116
|
|
|
HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT, |
117
|
|
|
HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT |
118
|
|
|
); |
119
|
|
|
$this->shouldAsk( |
120
|
|
|
HookQuestions::PRE_PUSH_ERROR_MESSAGE, |
121
|
|
|
HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT, |
122
|
|
|
HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT |
123
|
|
|
); |
124
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
125
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
126
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS); |
127
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
128
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE); |
129
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
130
|
|
|
$this->shouldAsk( |
131
|
|
|
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE, |
132
|
|
|
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT, |
133
|
|
|
ConfigArrayDataStub::ERROR_MESSAGE |
134
|
|
|
); |
135
|
|
|
$this->shouldHandleQuery(new GitIgnoreExtractorQuery(), GitIgnoreDataResponseStub::randomWithGuardCoverage()); |
136
|
|
|
$this->shouldCopyPrePushHook(); |
137
|
|
|
$this->shouldWriteConfigurationData(ConfigArrayDataStub::hooksEnabledWithEnabledTools()); |
138
|
|
|
|
139
|
|
|
$command = new ConfigurationProcessor($this->getIOInterface()); |
|
|
|
|
140
|
|
|
|
141
|
|
|
$this->configurationProcessorCommandHandler->handle($command); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @test |
146
|
|
|
*/ |
147
|
|
|
public function itShouldNotMakeAnyQuestions() |
148
|
|
|
{ |
149
|
|
|
$data = ConfigurationArrayTransformer::transform( |
150
|
|
|
PreCommitStub::createAllEnabled(), |
151
|
|
|
CommitMsgStub::createEnabled(), |
152
|
|
|
PrePushStub::createAllEnabled() |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$this->shouldReadConfigurationData(ConfigStub::createEnabled()); |
156
|
|
|
$this->shouldCopyPreCommitHook(); |
157
|
|
|
$this->shouldCopyCommitMsgHook(); |
158
|
|
|
$this->shouldCopyPrePushHook(); |
159
|
|
|
$this->shouldWriteConfigurationData($data); |
160
|
|
|
|
161
|
|
|
$command = new ConfigurationProcessor($this->getIOInterface()); |
|
|
|
|
162
|
|
|
|
163
|
|
|
$this->configurationProcessorCommandHandler->handle($command); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
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.