Completed
Branch guard_coverage (f2aaf0)
by Pablo
03:07
created

ConfigurationProcessorCommandHandlerTest   C

Complexity

Total Complexity 3

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 9
Bugs 1 Features 0
Metric Value
wmc 3
c 9
b 1
f 0
lcom 1
cbo 19
dl 0
loc 142
rs 6.875

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 27 1
B itShouldMakeAllQuestions() 0 81 1
A itShouldNotMakeAnyQuestions() 0 18 1
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(),
0 ignored issues
show
Bug introduced by
It seems like $this->getConfigurationFileReader() targeting PhpGitHooks\Module\Confi...nfigurationFileReader() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...rocessor::__construct() does only seem to accept object<PhpGitHooks\Modul...ionFileReaderInterface>, 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...
37
                new PreCommitProcessor(
38
                    new PhpUnitGuardCoverageConfigurator(
39
                        new PhpGuardCoverageGitIgnoreConfigurator(
40
                            $this->getQueryBus(),
0 ignored issues
show
Bug introduced by
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
Bug introduced by
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(),
0 ignored issues
show
Bug introduced by
It seems like $this->getConfigurationFileWriter() targeting PhpGitHooks\Module\Confi...nfigurationFileWriter() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...rocessor::__construct() does only seem to accept object<PhpGitHooks\Modul...ionFileWriterInterface>, 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...
47
                $this->getHookCopier(),
0 ignored issues
show
Bug introduced by
It seems like $this->getHookCopier() targeting PhpGitHooks\Module\Confi...rTrait::getHookCopier() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...rocessor::__construct() does only seem to accept object<PhpGitHooks\Modul...ucture\Hook\HookCopier>, 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...
48
                new PrePushProcessor(
49
                    new PhpUnitGuardCoverageConfigurator(
50
                        new PhpGuardCoverageGitIgnoreConfigurator(
51
                            $this->getQueryBus(),
0 ignored issues
show
Bug introduced by
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
Bug introduced by
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::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
93
        $this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
94
        $this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS);
95
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
96
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE);
97
        $this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
98
        $this->shouldAsk(
99
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE,
100
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT,
101
            ConfigArrayDataStub::ERROR_MESSAGE
102
        );
103
        $this->shouldHandleQuery(new GitIgnoreExtractorQuery(), $gitIgnoreDataResponse);
104
        $this->shouldHandleCommand(new GitIgnoreWriterCommand($gitIgnoreDataResponse->getContent()));
105
106
        $this->shouldAsk(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
107
        $this->shouldCopyPreCommitHook();
108
        $this->shouldAsk(
109
            HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION,
110
            HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER,
111
            ConfigArrayDataStub::REGULAR_EXPRESSION
112
        );
113
        $this->shouldCopyCommitMsgHook();
114
        $this->shouldAsk(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
115
        $this->shouldAsk(
116
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE,
117
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT,
118
            HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT
119
        );
120
        $this->shouldAsk(
121
            HookQuestions::PRE_PUSH_ERROR_MESSAGE,
122
            HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT,
123
            HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT
124
        );
125
        $this->shouldAsk(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
126
        $this->shouldAsk(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
127
        $this->shouldAsk(HookQuestions::PHPUNIT_OPTIONS, null, ConfigArrayDataStub::PHPUNIT_OPTIONS);
128
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
129
        $this->shouldAsk(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.00, ConfigArrayDataStub::MINIMUM_COVERAGE);
130
        $this->shouldAsk(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER, $yes);
131
        $this->shouldAsk(
132
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE,
133
            HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT,
134
            ConfigArrayDataStub::ERROR_MESSAGE
135
        );
136
        $this->shouldHandleQuery(new GitIgnoreExtractorQuery(), GitIgnoreDataResponseStub::randomWithGuardCoverage());
137
        $this->shouldCopyPrePushHook();
138
        $this->shouldWriteConfigurationData(ConfigArrayDataStub::hooksEnabledWithEnabledTools());
139
140
        $command = new ConfigurationProcessorCommand($this->getIOInterface());
0 ignored issues
show
Bug introduced by
It seems like $this->getIOInterface() targeting PhpGitHooks\Module\Confi...Trait::getIOInterface() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...rCommand::__construct() does only seem to accept object<Composer\IO\IOInterface>, 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...
141
142
        $this->configurationProcessorCommandHandler->handle($command);
143
    }
144
145
    /**
146
     * @test
147
     */
148
    public function itShouldNotMakeAnyQuestions()
149
    {
150
        $data = ConfigurationArrayTransformer::transform(
151
            PreCommitStub::createAllEnabled(),
152
            CommitMsgStub::createEnabled(),
153
            PrePushStub::createAllEnabled()
154
        );
155
156
        $this->shouldReadConfigurationData(ConfigStub::createEnabled());
157
        $this->shouldCopyPreCommitHook();
158
        $this->shouldCopyCommitMsgHook();
159
        $this->shouldCopyPrePushHook();
160
        $this->shouldWriteConfigurationData($data);
161
162
        $command = new ConfigurationProcessorCommand($this->getIOInterface());
0 ignored issues
show
Bug introduced by
It seems like $this->getIOInterface() targeting PhpGitHooks\Module\Confi...Trait::getIOInterface() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...rCommand::__construct() does only seem to accept object<Composer\IO\IOInterface>, 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...
163
164
        $this->configurationProcessorCommandHandler->handle($command);
165
    }
166
}
167