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

PrePushToolCommandHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
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\PhpUnitToolCommand;
15
16
class PrePushToolCommandHandlerTest extends GitUnitTestCase
17
{
18
    private $remote = 'origin';
19
    private $url = '[email protected]';
20
    /**
21
     * @var PrePushToolCommandHandler
22
     */
23
    private $prePushToolCommandHandler;
24
25
    protected function setUp()
26
    {
27
        $this->prePushToolCommandHandler = new PrePushToolCommandHandler(
28
            new PrePushTool(
29
                $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<CommandBus\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...
30
                $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...
31
                $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...
32
                $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<CommandBus\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...
33
            )
34
        );
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function itShouldNotExecuteHook()
41
    {
42
        $this->shouldHandleQuery(
43
            new ConfigurationDataFinderQuery(),
44
            ConfigurationDataResponseStub::createCustom(false, false, false)
45
        );
46
47
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function itShouldThrowsExceptionFromOriginalScript()
54
    {
55
        $this->expectException(InvalidPushException::class);
56
57
        $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
58
59
        $this->shouldHandleQuery(
60
            new ConfigurationDataFinderQuery(),
61
            $configurationDataResponse
62
        );
63
        $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK);
64
        $this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error');
65
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($configurationDataResponse->getPrePushErrorMessage()));
66
67
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function itShouldWorksFine()
74
    {
75
        $configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
76
77
        $this->shouldHandleQuery(
78
            new ConfigurationDataFinderQuery(),
79
            $configurationDataResponse
80
        );
81
        $this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK);
82
        $this->shouldExecutePrePushOriginal($this->remote, $this->url, '');
83
        $this->shouldHandleCommand(
84
            new PhpUnitToolCommand(
85
                $configurationDataResponse->isPrePushPhpUnitRandom(),
86
                $configurationDataResponse->getPrePushPhpUnitOptions(),
87
                $configurationDataResponse->getPrePushErrorMessage()
88
            )
89
        );
90
        $this->shouldWriteLnOutput(GoodJobLogoResponse::paint($configurationDataResponse->getPrePushRightMessage()));
91
92
        $this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url));
93
    }
94
}
95