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

ComposerToolHandlerTest::itShouldThrowException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace PhpGitHooks\Module\Composer\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool;
6
use PhpGitHooks\Module\Composer\Contract\Command\ComposerToolHandler;
7
use PhpGitHooks\Module\Composer\Contract\Exception\ComposerFilesNotFoundException;
8
use PhpGitHooks\Module\Composer\Tests\Infrastructure\ComposerUnitTestCase;
9
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
10
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractor;
11
use PhpGitHooks\Module\Files\Tests\Stub\ComposerFilesResponseStub;
12
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
13
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
14
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
15
16
class ComposerToolHandlerTest extends ComposerUnitTestCase
17
{
18
    /**
19
     * @var ComposerToolHandler
20
     */
21
    private $composerToolCommandHandler;
22
    /**
23
     * @var string
24
     */
25
    private $errorMessage;
26
27
    protected function setUp()
28
    {
29
        $this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
30
        $this->composerToolCommandHandler = new ComposerToolHandler(
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\Compo...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...
32
            $this->getOutputInterface()
33
        );
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function itShouldWorksFine()
40
    {
41
        $files = FilesCommittedStub::createAllFiles();
42
43
        $output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE);
44
        $this->shouldWriteOutput($output->getMessage());
45
        $this->shouldHandleQuery(
46
            new ComposerFilesExtractor($files),
47
            ComposerFilesResponseStub::createValidData()
48
        );
49
        $this->shouldWriteLnOutput($output->getSuccessfulMessage());
50
51
        $this->composerToolCommandHandler->handle(
52
            new ComposerTool($files, $this->errorMessage)
53
        );
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function itShouldThrowException()
60
    {
61
        $this->expectException(ComposerFilesNotFoundException::class);
62
63
        $files = FilesCommittedStub::createInvalidComposerFiles();
64
        $output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE);
65
66
        $this->shouldWriteOutput($output->getMessage());
67
        $this->shouldHandleQuery(
68
            new ComposerFilesExtractor($files),
69
            ComposerFilesResponseStub::createInvalidData()
70
        );
71
        $this->shouldWriteLnOutput($output->getFailMessage());
72
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
73
74
        $this->composerToolCommandHandler->handle(
75
            new ComposerTool($files, $this->errorMessage)
76
        );
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function itShouldNotExecuteComposerTool()
83
    {
84
        $files = FilesCommittedStub::createWithoutComposerFiles();
85
86
        $this->shouldHandleQuery(
87
            new ComposerFilesExtractor($files),
88
            ComposerFilesResponseStub::createNoData()
89
        );
90
91
        $this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage));
92
    }
93
}
94