Completed
Branch module_structure (3116d9)
by Pablo
02:56
created

ConfigurationProcessorCommandHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 1
cbo 13
dl 0
loc 106
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
A itShouldMakeAllQuestions() 0 59 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\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(),
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...
32
                new PreCommitProcessor(),
33
                new CommitMsgProcessor(),
34
                $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...
35
                $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...
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());
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...
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());
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...
122
123
        $this->configurationProcessorCommandHandler->handle($command);
124
    }
125
}
126