1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Configuration\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Contract\Command\ConfigurationProcessorCommand; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Contract\CommandHandler\ConfigurationProcessorCommandHandler; |
7
|
|
|
use PhpGitHooks\Module\Configuration\Service\CommitMsgProcessor; |
8
|
|
|
use PhpGitHooks\Module\Configuration\Service\ConfigurationArrayTransformer; |
9
|
|
|
use PhpGitHooks\Module\Configuration\Service\ConfigurationProcessor; |
10
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
11
|
|
|
use PhpGitHooks\Module\Configuration\Service\PreCommitProcessor; |
12
|
|
|
use PhpGitHooks\Module\Configuration\Service\PrePushProcessor; |
13
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Infrastructure\ConfigurationUnitTestCase; |
14
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\CommitMsgStub; |
15
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigArrayDataStub; |
16
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigStub; |
17
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitStub; |
18
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PrePushStub; |
19
|
|
|
|
20
|
|
|
final class ConfigurationProcessorCommandHandlerTest extends ConfigurationUnitTestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ConfigurationProcessorCommandHandler |
24
|
|
|
*/ |
25
|
|
|
private $configurationProcessorCommandHandler; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->configurationProcessorCommandHandler = new ConfigurationProcessorCommandHandler( |
30
|
|
|
new ConfigurationProcessor( |
31
|
|
|
$this->getConfigurationFileReader(), |
|
|
|
|
32
|
|
|
new PreCommitProcessor(), |
33
|
|
|
new CommitMsgProcessor(), |
34
|
|
|
$this->getConfigurationFileWriter(), |
|
|
|
|
35
|
|
|
$this->getHookCopier(), |
|
|
|
|
36
|
|
|
new PrePushProcessor() |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @test |
43
|
|
|
*/ |
44
|
|
|
public function itShouldMakeAllQuestions() |
45
|
|
|
{ |
46
|
|
|
$this->shouldReadConfigurationData(ConfigStub::createUndefined()); |
47
|
|
|
|
48
|
|
|
$yes = 'y'; |
49
|
|
|
$this->shouldAsk(HookQuestions::PRE_COMMIT_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
50
|
|
|
$this->shouldAsk( |
51
|
|
|
HookQuestions::PRE_COMMIT_RIGHT_MESSAGE, |
52
|
|
|
HookQuestions::PRE_COMMIT_RIGHT_MESSAGE_DEFAULT, |
53
|
|
|
ConfigArrayDataStub::RIGHT_MESSAGE |
54
|
|
|
); |
55
|
|
|
$this->shouldAsk( |
56
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE, |
57
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, |
58
|
|
|
ConfigArrayDataStub::ERROR_MESSAGE |
59
|
|
|
); |
60
|
|
|
$this->shouldAsk(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
61
|
|
|
$this->shouldAsk(HookQuestions::JSONLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
62
|
|
|
$this->shouldAsk(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
63
|
|
|
$this->shouldAsk(HookQuestions::PHPMD_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
64
|
|
|
$this->shouldAsk(HookQuestions::PHPCS_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
65
|
|
|
$this->shouldAsk(HookQuestions::PHPCS_STANDARD, null, ConfigArrayDataStub::PHPCS_STANDARD); |
66
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
67
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR0_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
68
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR1_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
69
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_PSR2_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
70
|
|
|
$this->shouldAsk(HookQuestions::PHPCSFIXER_SYMFONY_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
71
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
72
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
73
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS); |
74
|
|
|
$this->shouldAsk(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
75
|
|
|
$this->shouldCopyPreCommitHook(); |
76
|
|
|
$this->shouldAsk( |
77
|
|
|
HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION, |
78
|
|
|
HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER, |
79
|
|
|
ConfigArrayDataStub::REGULAR_EXPRESSION |
80
|
|
|
); |
81
|
|
|
$this->shouldCopyCommitMsgHook(); |
82
|
|
|
$this->shouldAsk(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
83
|
|
|
$this->shouldAsk( |
84
|
|
|
HookQuestions::PRE_PUSH_RIGHT_MESSAGE, |
85
|
|
|
HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT, |
86
|
|
|
ConfigArrayDataStub::RIGHT_MESSAGE |
87
|
|
|
); |
88
|
|
|
$this->shouldAsk( |
89
|
|
|
HookQuestions::PRE_PUSH_ERROR_MESSAGE, |
90
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT, |
91
|
|
|
ConfigArrayDataStub::ERROR_MESSAGE |
92
|
|
|
); |
93
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
94
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes); |
95
|
|
|
$this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS); |
96
|
|
|
$this->shouldCopyPrePushHook(); |
97
|
|
|
$this->shouldWriteConfigurationData(ConfigArrayDataStub::hooksEnabledWithEnabledTools()); |
98
|
|
|
|
99
|
|
|
$command = new ConfigurationProcessorCommand($this->getIOInterface()); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$this->configurationProcessorCommandHandler->handle($command); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @test |
106
|
|
|
*/ |
107
|
|
|
public function itShouldNotMakeAnyQuestions() |
108
|
|
|
{ |
109
|
|
|
$data = ConfigurationArrayTransformer::transform( |
110
|
|
|
PreCommitStub::createAllEnabled(), |
111
|
|
|
CommitMsgStub::createEnabled(), |
112
|
|
|
PrePushStub::createAllEnabled() |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->shouldReadConfigurationData(ConfigStub::createEnabled()); |
116
|
|
|
$this->shouldCopyPreCommitHook(); |
117
|
|
|
$this->shouldCopyCommitMsgHook(); |
118
|
|
|
$this->shouldCopyPrePushHook(); |
119
|
|
|
$this->shouldWriteConfigurationData($data); |
120
|
|
|
|
121
|
|
|
$command = new ConfigurationProcessorCommand($this->getIOInterface()); |
|
|
|
|
122
|
|
|
|
123
|
|
|
$this->configurationProcessorCommandHandler->handle($command); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.