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

itShouldNotExecuteHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace PhpGitHooks\Module\Git\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinderQuery;
6
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub;
7
use PhpGitHooks\Module\Git\Contract\Command\PrePushToolCommand;
8
use PhpGitHooks\Module\Git\Contract\CommandHandler\PrePushToolCommandHandler;
9
use PhpGitHooks\Module\Git\Contract\Exception\InvalidPushException;
10
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
11
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse;
12
use PhpGitHooks\Module\Git\Service\PrePushTool;
13
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase;
14
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand;
15
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolCommand;
16
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageCommand;
17
18
class PrePushToolCommandHandlerTest extends GitUnitTestCase
19
{
20
    private $remote = 'origin';
21
    private $url = '[email protected]';
22
    /**
23
     * @var PrePushToolCommandHandler
24
     */
25
    private $prePushToolCommandHandler;
26
27
    protected function setUp()
28
    {
29
        $this->prePushToolCommandHandler = new PrePushToolCommandHandler(
30
            new PrePushTool(
31
                $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\S...PushTool::__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...
32
                $this->getPrePushOriginalExecutor(),
0 ignored issues
show
Bug introduced by
It seems like $this->getPrePushOriginalExecutor() targeting PhpGitHooks\Module\Git\T...ePushOriginalExecutor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Git\S...PushTool::__construct() does only seem to accept object<PhpGitHooks\Modul...ginalExecutorInterface>, 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...
33
                $this->getOutputInterface(),
0 ignored issues
show
Bug introduced by
It seems like $this->getOutputInterface() targeting PhpGitHooks\Module\Git\T...t::getOutputInterface() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Git\S...PushTool::__construct() does only seem to accept object<Symfony\Component...Output\OutputInterface>, 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...
34
                $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\S...PushTool::__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...
35
            )
36
        );
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function itShouldNotExecuteHook()
43
    {
44
        $this->shouldHandleQuery(
45
            new ConfigurationDataFinderQuery(),
46
            ConfigurationDataResponseStub::createCustom(false, false, false)
47
        );
48
49
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function itShouldThrowsExceptionFromOriginalScript()
56
    {
57
        $this->expectException(InvalidPushException::class);
58
59
        $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
60
61
        $this->shouldHandleQuery(
62
            new ConfigurationDataFinderQuery(),
63
            $configurationDataResponse
64
        );
65
        $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK);
66
        $this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error');
67
        $this->shouldWriteLnOutput(
68
            BadJobLogoResponse::paint($configurationDataResponse->getPrePush()->getErrorMessage())
69
        );
70
71
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
72
    }
73
74
    /**
75
     * @test
76
     */
77
    public function itShouldWorksFine()
78
    {
79
        $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
80
81
        $this->shouldHandleQuery(
82
            new ConfigurationDataFinderQuery(),
83
            $configurationDataResponse
84
        );
85
        $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK);
86
        $this->shouldExecutePrePushOriginal($this->remote, $this->url, '');
87
        $this->shouldHandleCommand(
88
            new PhpUnitToolCommand(
89
                $configurationDataResponse->getPrePush()->getPhpUnit()->isPhpunitRandomMode(),
90
                $configurationDataResponse->getPrePush()->getPhpUnit()->getPhpunitOptions(),
91
                $configurationDataResponse->getPrePush()->getErrorMessage()
92
            )
93
        );
94
        $this->shouldHandleCommand(
95
            new StrictCoverageCommand(
96
                $configurationDataResponse->getPrePush()->getPhpUnitStrictCoverage()->getMinimum(),
97
                $configurationDataResponse->getPrePush()->getErrorMessage()
98
            )
99
        );
100
101
        $this->shouldHandleCommand(
102
            new GuardCoverageCommand(
103
                $configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage()
104
            )
105
        );
106
107
        $this->shouldWriteLnOutput(
108
            GoodJobLogoResponse::paint($configurationDataResponse->getPrePush()->getRightMessage())
109
        );
110
111
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
112
    }
113
}
114