Completed
Push — master ( deb1d5...3324ab )
by Pablo
04:13
created

Tests/Behaviour/ComposerToolCommandHandlerTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PhpGitHooks\Module\Composer\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Composer\Contract\Command\ComposerToolCommand;
6
use PhpGitHooks\Module\Composer\Contract\CommandHandler\ComposerToolCommandHandler;
7
use PhpGitHooks\Module\Composer\Contract\Exception\ComposerFilesNotFoundException;
8
use PhpGitHooks\Module\Composer\Service\ComposerTool;
9
use PhpGitHooks\Module\Composer\Tests\Infrastructure\ComposerUnitTestCase;
10
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
11
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractorQuery;
12
use PhpGitHooks\Module\Files\Tests\Stub\ComposerFilesResponseStub;
13
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
14
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
15
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
16
17
class ComposerToolCommandHandlerTest extends ComposerUnitTestCase
18
{
19
    /**
20
     * @var ComposerToolCommandHandler
21
     */
22
    private $composerToolCommandHandler;
23
    /**
24
     * @var string
25
     */
26
    private $errorMessage;
27
28
    protected function setUp()
29
    {
30
        $this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
31
        $this->composerToolCommandHandler = new ComposerToolCommandHandler(
32
            new ComposerTool(
33
                $this->getQueryBus(),
0 ignored issues
show
It seems like $this->getQueryBus() targeting PhpGitHooks\Module\Share...BusTrait::getQueryBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Compo...oserTool::__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...
34
                $this->getOutputInterface()
35
            )
36
        );
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function itShouldWorksFine()
43
    {
44
        $files = FilesCommittedStub::createAllFiles();
45
46
        $output = new PreCommitOutputWriter(ComposerTool::CHECKING_MESSAGE);
47
        $this->shouldWriteOutput($output->getMessage());
48
        $this->shouldHandleQuery(
49
            new ComposerFilesExtractorQuery($files),
50
            ComposerFilesResponseStub::createValidData()
51
        );
52
        $this->shouldWriteLnOutput($output->getSuccessfulMessage());
53
54
        $this->composerToolCommandHandler->handle(
55
            new ComposerToolCommand($files, $this->errorMessage)
56
        );
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function itShouldThrowException()
63
    {
64
        $this->expectException(ComposerFilesNotFoundException::class);
65
66
        $files = FilesCommittedStub::createInvalidComposerFiles();
67
        $output = new PreCommitOutputWriter(ComposerTool::CHECKING_MESSAGE);
68
69
        $this->shouldWriteOutput($output->getMessage());
70
        $this->shouldHandleQuery(
71
            new ComposerFilesExtractorQuery($files),
72
            ComposerFilesResponseStub::createInvalidData()
73
        );
74
        $this->shouldWriteLnOutput($output->getFailMessage());
75
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
76
77
        $this->composerToolCommandHandler->handle(
78
            new ComposerToolCommand($files, $this->errorMessage)
79
        );
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function itShouldNotExecuteComposerTool()
86
    {
87
        $files = FilesCommittedStub::createWithoutComposerFiles();
88
89
        $this->shouldHandleQuery(
90
            new ComposerFilesExtractorQuery($files),
91
            ComposerFilesResponseStub::createNoData()
92
        );
93
94
        $this->composerToolCommandHandler->handle(new ComposerToolCommand($files, $this->errorMessage));
95
    }
96
}
97