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