Completed
Push — master ( 236db5...b6d10e )
by Pablo
7s
created

PhpMdToolCommandHandlerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 9
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
B itShouldThrowsException() 0 25 2
A itShouldWorksFine() 0 18 2
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