Completed
Push — master ( deb1d5...3324ab )
by Pablo
04:13
created

ConfigurationProcessorCommandHandlerTest.php (4 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\PhpGuardCoverageGitIgnoreConfigurator;
12
use PhpGitHooks\Module\Configuration\Service\PhpUnitGuardCoverageConfigurator;
13
use PhpGitHooks\Module\Configuration\Service\PreCommitProcessor;
14
use PhpGitHooks\Module\Configuration\Service\PrePushProcessor;
15
use PhpGitHooks\Module\Configuration\Tests\Infrastructure\ConfigurationUnitTestCase;
16
use PhpGitHooks\Module\Configuration\Tests\Stub\CommitMsgStub;
17
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigArrayDataStub;
18
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigStub;
19
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitStub;
20
use PhpGitHooks\Module\Configuration\Tests\Stub\PrePushStub;
21
use PhpGitHooks\Module\Git\Contract\Command\GitIgnoreWriterCommand;
22
use PhpGitHooks\Module\Git\Contract\Query\GitIgnoreExtractorQuery;
23
use PhpGitHooks\Module\Git\Tests\Stub\GitIgnoreDataResponseStub;
24
25
final class ConfigurationProcessorCommandHandlerTest extends ConfigurationUnitTestCase
26
{
27
    /**
28
     * @var ConfigurationProcessorCommandHandler
29
     */
30
    private $configurationProcessorCommandHandler;
31
32
    protected function setUp()
33
    {
34
        $this->configurationProcessorCommandHandler = new ConfigurationProcessorCommandHandler(
35
            new ConfigurationProcessor(
36
                $this->getConfigurationFileReader(),
37
                new PreCommitProcessor(
38
                    new PhpUnitGuardCoverageConfigurator(
39
                        new PhpGuardCoverageGitIgnoreConfigurator(
40
                            $this->getQueryBus(),
0 ignored issues
show
It seems like $this->getQueryBus() targeting PhpGitHooks\Module\Share...BusTrait::getQueryBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...dBus\QueryBus\QueryBus>, maybe add an additional type check?

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.

Loading history...
41
                            $this->getCommandBus()
0 ignored issues
show
It seems like $this->getCommandBus() targeting PhpGitHooks\Module\Share...sTrait::getCommandBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...\CommandBus\CommandBus>, maybe add an additional type check?

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.

Loading history...
42
                        )
43
                    )
44
                ),
45
                new CommitMsgProcessor(),
46
                $this->getConfigurationFileWriter(),
47
                $this->getHookCopier(),
48
                new PrePushProcessor(
49
                    new PhpUnitGuardCoverageConfigurator(
50
                        new PhpGuardCoverageGitIgnoreConfigurator(
51
                            $this->getQueryBus(),
0 ignored issues
show
It seems like $this->getQueryBus() targeting PhpGitHooks\Module\Share...BusTrait::getQueryBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...dBus\QueryBus\QueryBus>, maybe add an additional type check?

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.

Loading history...
52
                            $this->getCommandBus()
0 ignored issues
show
It seems like $this->getCommandBus() targeting PhpGitHooks\Module\Share...sTrait::getCommandBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...\CommandBus\CommandBus>, maybe add an additional type check?

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.

Loading history...
53
                        )
54
                    )
55
                )
56
            )
57
        );
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function itShouldMakeAllQuestions()
64
    {
65
        $yes = 'y';
66
        $gitIgnoreDataResponse = GitIgnoreDataResponseStub::random();
67
68
        $this->shouldReadConfigurationData(ConfigStub::createUndefined());
69
        $this->shouldAsk(HookQuestions::PRE_COMMIT_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
70
        $this->shouldAsk(
71
            HookQuestions::PRE_COMMIT_RIGHT_MESSAGE,
72
            HookQuestions::PRE_COMMIT_RIGHT_MESSAGE_DEFAULT,
73
            ConfigArrayDataStub::RIGHT_MESSAGE
74
        );
75
        $this->shouldAsk(
76
            HookQuestions::PRE_COMMIT_ERROR_MESSAGE,
77
            HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT,
78
            ConfigArrayDataStub::ERROR_MESSAGE
79
        );
80
        $this->shouldAsk(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
81
        $this->shouldAsk(HookQuestions::JSONLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
82
        $this->shouldAsk(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
83
        $this->shouldAsk(HookQuestions::PHPMD_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
84
        $this->shouldAsk(HookQuestions::PHPMD_OPTIONS, null, ConfigArrayDataStub::PHPMD_OPTIONS);
85
        $this->shouldAsk(HookQuestions::PHPCS_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
86
        $this->shouldAsk(HookQuestions::PHPCS_STANDARD, null, ConfigArrayDataStub::PHPCS_STANDARD);
87
        $this->shouldAsk(HookQuestions::PHPCSFIXER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
88
        $this->shouldAsk(HookQuestions::PHPCSFIXER_PSR0_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
89
        $this->shouldAsk(HookQuestions::PHPCSFIXER_PSR1_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
90
        $this->shouldAsk(HookQuestions::PHPCSFIXER_PSR2_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
91
        $this->shouldAsk(HookQuestions::PHPCSFIXER_SYMFONY_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
92
        $this->shouldAsk(HookQuestions::PHPCSFIXER_OPTIONS, null, ConfigArrayDataStub::PHPCSFIXER_OPTIONS);
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->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
97
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE);
98
        $this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
99
        $this->shouldAsk(
100
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE,
101
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT,
102
            ConfigArrayDataStub::ERROR_MESSAGE
103
        );
104
        $this->shouldHandleQuery(new GitIgnoreExtractorQuery(), $gitIgnoreDataResponse);
105
        $this->shouldHandleCommand(new GitIgnoreWriterCommand($gitIgnoreDataResponse->getContent()));
106
107
        $this->shouldAsk(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
108
        $this->shouldCopyPreCommitHook();
109
        $this->shouldAsk(
110
            HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION,
111
            HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER,
112
            ConfigArrayDataStub::REGULAR_EXPRESSION
113
        );
114
        $this->shouldCopyCommitMsgHook();
115
        $this->shouldAsk(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
116
        $this->shouldAsk(
117
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE,
118
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT,
119
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT
120
        );
121
        $this->shouldAsk(
122
            HookQuestions::PRE_PUSH_ERROR_MESSAGE,
123
            HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT,
124
            HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT
125
        );
126
        $this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
127
        $this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
128
        $this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS);
129
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
130
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE);
131
        $this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
132
        $this->shouldAsk(
133
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE,
134
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT,
135
            ConfigArrayDataStub::ERROR_MESSAGE
136
        );
137
        $this->shouldHandleQuery(new GitIgnoreExtractorQuery(), GitIgnoreDataResponseStub::randomWithGuardCoverage());
138
        $this->shouldCopyPrePushHook();
139
        $this->shouldWriteConfigurationData(ConfigArrayDataStub::hooksEnabledWithEnabledTools());
140
141
        $command = new ConfigurationProcessorCommand($this->getIOInterface());
142
143
        $this->configurationProcessorCommandHandler->handle($command);
144
    }
145
146
    /**
147
     * @test
148
     */
149
    public function itShouldNotMakeAnyQuestions()
150
    {
151
        $data = ConfigurationArrayTransformer::transform(
152
            PreCommitStub::createAllEnabled(),
153
            CommitMsgStub::createEnabled(),
154
            PrePushStub::createAllEnabled()
155
        );
156
157
        $this->shouldReadConfigurationData(ConfigStub::createEnabled());
158
        $this->shouldCopyPreCommitHook();
159
        $this->shouldCopyCommitMsgHook();
160
        $this->shouldCopyPrePushHook();
161
        $this->shouldWriteConfigurationData($data);
162
163
        $command = new ConfigurationProcessorCommand($this->getIOInterface());
164
165
        $this->configurationProcessorCommandHandler->handle($command);
166
    }
167
}
168