Completed
Push — master ( efc44e...835840 )
by Pablo
02:59
created

PreCommitToolHandlerTest   C

Complexity

Total Complexity 3

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 28

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 28
dl 0
loc 108
rs 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A itShouldNotExecuteTools() 0 8 1
A itShouldExecuteAllTools() 0 74 1
1
<?php
2
3
namespace PhpGitHooks\Module\Git\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool;
6
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinder;
7
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
8
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub;
9
use PhpGitHooks\Module\Files\Contract\Query\PhpFilesExtractor;
10
use PhpGitHooks\Module\Files\Tests\Stub\PhpFilesResponseStub;
11
use PhpGitHooks\Module\Git\Contract\Command\PreCommitTool;
12
use PhpGitHooks\Module\Git\Contract\Command\PreCommitToolHandler;
13
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse;
14
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase;
15
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
16
use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintToolCommand;
17
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsToolCommand;
18
use PhpGitHooks\Module\PhpCsFixer\Contract\Command\PhpCsFixerToolCommand;
19
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintToolCommand;
20
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdToolCommand;
21
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand;
22
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolCommand;
23
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageCommand;
24
use PhpGitHooks\Module\Tests\Infrastructure\Stub\StubCreator;
25
26
class PreCommitToolHandlerTest extends GitUnitTestCase
27
{
28
    /**
29
     * @var PreCommitToolHandler
30
     */
31
    private $preCommitToolCommandHandler;
32
33
    protected function setUp()
34
    {
35
        $this->preCommitToolCommandHandler = new PreCommitToolHandler(
36
            $this->getOutputInterface(),
37
            $this->getFilesCommittedExtractor(),
0 ignored issues
show
Bug introduced by
It seems like $this->getFilesCommittedExtractor() targeting PhpGitHooks\Module\Git\T...lesCommittedExtractor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Git\C...lHandler::__construct() does only seem to accept object<PhpGitHooks\Modul...ilesCommittedExtractor>, 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...
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\Git\C...lHandler::__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\Git\C...lHandler::__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
            $this->getToolTitleOutputWriter()
0 ignored issues
show
Bug introduced by
It seems like $this->getToolTitleOutputWriter() targeting PhpGitHooks\Module\Git\T...ToolTitleOutputWriter() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Git\C...lHandler::__construct() does only seem to accept object<PhpGitHooks\Modul...ToolTittleOutputWriter>, 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
        );
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function itShouldNotExecuteTools()
48
    {
49
        $this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title');
50
        $this->shouldGetFilesCommitted([StubCreator::faker()->sha1]);
51
        $this->shouldWriteLnOutput(PreCommitToolHandler::NO_FILES_CHANGED_MESSAGE);
52
53
        $this->preCommitToolCommandHandler->handle(new PreCommitTool());
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function itShouldExecuteAllTools()
60
    {
61
        $files = FilesCommittedStub::createAllFiles();
62
        $configurationDataResponse = ConfigurationDataResponseStub::createAllEnabled();
63
64
        $this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title');
65
        $this->shouldGetFilesCommitted($files);
66
        $this->shouldHandleQuery(new ConfigurationDataFinder(), $configurationDataResponse);
67
        $this->shouldHandleCommand(
68
            new ComposerTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
69
        );
70
        $this->shouldHandleCommand(
71
            new JsonLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
72
        );
73
        $this->shouldHandleQuery(
74
            new PhpFilesExtractor($files),
75
            PhpFilesResponseStub::create(FilesCommittedStub::createWithoutPhpFiles())
76
        );
77
        $this->shouldHandleCommand(
78
            new PhpLintToolCommand($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
79
        );
80
        $this->shouldHandleCommand(
81
            new PhpCsToolCommand(
82
                $files,
83
                $configurationDataResponse->getPreCommit()->getPhpCs()->getPhpCsStandard(),
84
                HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT,
85
                $configurationDataResponse->getPreCommit()->getPhpCs()->getIgnore()
86
            )
87
        );
88
        $this->shouldHandleCommand(
89
            new PhpCsFixerToolCommand(
90
                $files,
91
                $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(),
92
                $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(),
93
                $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(),
94
                $configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(),
95
                $configurationDataResponse->getPreCommit()->getPhpCsFixer()->getPhpCsFixerOptions(),
96
                $configurationDataResponse->getPreCommit()->getErrorMessage()
97
            )
98
        );
99
        $this->shouldHandleCommand(
100
            new PhpMdToolCommand(
101
                $files,
102
                $configurationDataResponse->getPreCommit()->getPhpMd()->getPhpMdOptions(),
103
                $configurationDataResponse->getPreCommit()->getErrorMessage()
104
            )
105
        );
106
        $this->shouldHandleCommand(
107
            new PhpUnitToolCommand(
108
                $configurationDataResponse->getPreCommit()->getPhpUnit()->isPhpunitRandomMode(),
109
                $configurationDataResponse->getPreCommit()->getPhpUnit()->getPhpunitOptions(),
110
                $configurationDataResponse->getPreCommit()->getErrorMessage()
111
            )
112
        );
113
114
        $this->shouldHandleCommand(
115
            new StrictCoverageCommand(
116
                $configurationDataResponse->getPreCommit()->getPhpUnitStrictCoverage()->getMinimum(),
117
                $configurationDataResponse->getPreCommit()->getErrorMessage()
118
            )
119
        );
120
121
        $this->shouldHandleCommand(
122
            new GuardCoverageCommand(
123
                $configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage()
124
            )
125
        );
126
127
        $this->shouldWriteLnOutput(
128
            GoodJobLogoResponse::paint($configurationDataResponse->getPreCommit()->getRightMessage())
129
        );
130
131
        $this->preCommitToolCommandHandler->handle(new PreCommitTool());
132
    }
133
}
134