Completed
Push — master ( 8ee32e...efc44e )
by Pablo
02:33
created

itShouldMakeAllQuestions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 83
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 83
rs 8.7468
cc 1
eloc 70
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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(),
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...rHandler::__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...
35
            new PreCommitProcessor(
36
                new PhpUnitGuardCoverageConfigurator(
37
                    new PhpGuardCoverageGitIgnoreConfigurator(
38
                        $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<Bruli\EventBusBundle\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...
39
                        $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<Bruli\EventBusBun...\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...
40
                    )
41
                )
42
            ),
43
            new CommitMsgProcessor(),
44
            $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...rHandler::__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...
45
            $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...rHandler::__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...
46
            new PrePushProcessor(
47
                new PhpUnitGuardCoverageConfigurator(
48
                    new PhpGuardCoverageGitIgnoreConfigurator(
49
                        $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<Bruli\EventBusBundle\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...
50
                        $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<Bruli\EventBusBun...\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...
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());
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...rocessor::__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...
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());
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...rocessor::__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...
162
163
        $this->configurationProcessorCommandHandler->handle($command);
164
    }
165
}
166