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

itShouldThrowsException()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
3
namespace PhpGitHooks\Module\PhpMd\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
6
use PhpGitHooks\Module\Configuration\Tests\Stub\PhpMdOptionsStub;
7
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
8
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
9
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
10
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdToolCommand;
11
use PhpGitHooks\Module\PhpMd\Contract\CommandHandler\PhpMdToolCommandHandler;
12
use PhpGitHooks\Module\PhpMd\Contract\Exception\PhpMdViolationsException;
13
use PhpGitHooks\Module\PhpMd\Service\PhpMdTool;
14
use PhpGitHooks\Module\PhpMd\Tests\Infrastructure\PhpMdUnitTestCase;
15
16
class PhpMdToolCommandHandlerTest extends PhpMdUnitTestCase
17
{
18
    /**
19
     * @var PhpMdToolCommandHandler
20
     */
21
    private $phpMdToolCommandHandler;
22
23
    protected function setUp()
24
    {
25
        $this->phpMdToolCommandHandler = new PhpMdToolCommandHandler(
26
            new PhpMdTool(
27
                $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\PhpMd...hpMdTool::__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...
28
                $this->getPhpMdToolProcessor()
0 ignored issues
show
Bug introduced by
It seems like $this->getPhpMdToolProcessor() targeting PhpGitHooks\Module\PhpMd...getPhpMdToolProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpMd...hpMdTool::__construct() does only seem to accept object<PhpGitHooks\Modul...ToolProcessorInterface>, 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...
29
            )
30
        );
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function itShouldThrowsException()
37
    {
38
        $this->expectException(PhpMdViolationsException::class);
39
40
        $phpMdOptions = PhpMdOptionsStub::random();
41
        $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
42
        $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
43
44
        $outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE);
45
        $this->shouldWriteOutput($outputMessage->getMessage());
46
47
        $errorsText = null;
48
        foreach ($phpFiles as $phpFile) {
49
            $error = 'ERROR';
50
            $this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), $error);
51
            $errorsText .= $error;
52
        }
53
54
        $this->shouldWriteLnOutput($outputMessage->getFailMessage());
55
        $this->shouldWriteLnOutput($outputMessage->setError($errorsText));
56
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage));
57
58
        $command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage);
59
        $this->phpMdToolCommandHandler->handle($command);
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function itShouldWorksFine()
66
    {
67
        $phpMdOptions = PhpMdOptionsStub::random();
68
        $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
69
        $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
70
71
        $outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE);
72
        $this->shouldWriteOutput($outputMessage->getMessage());
73
74
        foreach ($phpFiles as $phpFile) {
75
            $this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), null);
76
        }
77
78
        $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
79
80
        $command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage);
81
        $this->phpMdToolCommandHandler->handle($command);
82
    }
83
}
84