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

PhpLintToolCommandHandlerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 26.56 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 7
dl 17
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
B itShouldThrowsException() 0 25 2
A itShouldWorksFine() 17 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PhpGitHooks\Module\PhpLint\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
6
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
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\PhpLint\Contract\Command\PhpLintToolCommand;
11
use PhpGitHooks\Module\PhpLint\Contract\CommandHandler\PhpLintToolCommandHandler;
12
use PhpGitHooks\Module\PhpLint\Contract\Exception\PhpLintViolationsException;
13
use PhpGitHooks\Module\PhpLint\Service\PhpLintTool;
14
use PhpGitHooks\Module\PhpLint\Tests\Infrastructure\PhpLintUnitTestCase;
15
16
class PhpLintToolCommandHandlerTest extends PhpLintUnitTestCase
17
{
18
    /**
19
     * @var PhpLintToolCommandHandler
20
     */
21
    private $phpLintToolCommandHandler;
22
23
    protected function setUp()
24
    {
25
        $this->phpLintToolCommandHandler = new PhpLintToolCommandHandler(
26
            new PhpLintTool($this->getPhpLintToolProcessor(), $this->getOutputInterface())
0 ignored issues
show
Bug introduced by
It seems like $this->getPhpLintToolProcessor() targeting PhpGitHooks\Module\PhpLi...tPhpLintToolProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpLi...LintTool::__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...
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\PhpLi...LintTool::__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...
27
        );
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function itShouldThrowsException()
34
    {
35
        $this->expectException(PhpLintViolationsException::class);
36
37
        $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
38
        $outputMessage = new PreCommitOutputWriter(PhpLintTool::RUNNING_PHPLINT);
39
        $errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
40
41
        $this->shouldWriteOutput($outputMessage->getMessage());
42
43
        $errors = null;
44
        foreach ($phpFiles as $file) {
45
            $error = 'ERROR';
46
            $this->shouldProcessPhpLintTool($file, $error);
47
            $errors .= $error;
48
        }
49
50
        $this->shouldWriteLnOutput($outputMessage->getFailMessage());
51
        $this->shouldWriteLnOutput($outputMessage->setError($errors));
52
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage));
53
54
        $this->phpLintToolCommandHandler->handle(
55
            new PhpLintToolCommand($phpFiles, $errorMessage)
56
        );
57
    }
58
59
    /**
60
     * @test
61
     */
62 View Code Duplication
    public function itShouldWorksFine()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $phpFiles = FilesCommittedStub::createOnlyPhpFiles();
65
        $outputMessage = new PreCommitOutputWriter(PhpLintTool::RUNNING_PHPLINT);
66
67
        $this->shouldWriteOutput($outputMessage->getMessage());
68
69
        foreach ($phpFiles as $file) {
70
            $this->shouldProcessPhpLintTool($file, null);
71
        }
72
73
        $this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
74
75
        $this->phpLintToolCommandHandler->handle(
76
            new PhpLintToolCommand($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)
77
        );
78
    }
79
}
80