Completed
Push — master ( 835840...ce2316 )
by Pablo
02:59
created

StrictCoverageToolHandlerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 27.54 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
dl 19
loc 69
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A itShouldThrowsException() 0 14 1
A itShouldWorksFine() 19 19 1
A buildStrictCoverageSuccessfulMessage() 0 4 1

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\PhpUnit\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigArrayDataStub;
6
use PhpGitHooks\Module\Configuration\Tests\Stub\MinimumStrictCoverageStub;
7
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
8
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
9
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverage;
10
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageToolHandler;
11
use PhpGitHooks\Module\PhpUnit\Contract\Exception\InvalidStrictCoverageException;
12
use PhpGitHooks\Module\PhpUnit\Service\StrictCoverageTool;
13
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase;
14
15
class StrictCoverageToolHandlerTest extends PhpUnitUnitTestCase
16
{
17
    /**
18
     * @var string
19
     */
20
    private $errorMessage;
21
    /**
22
     * @var StrictCoverageToolHandler
23
     */
24
    private $strictCoverageToolCommandHandler;
25
26
    protected function setUp()
27
    {
28
        $this->errorMessage = ConfigArrayDataStub::ERROR_MESSAGE;
29
        $this->strictCoverageToolCommandHandler = new StrictCoverageToolHandler(
30
            $this->getOutputInterface(),
31
            new StrictCoverageTool(
32
                $this->getStrictCoverageProcessor(),
0 ignored issues
show
Bug introduced by
It seems like $this->getStrictCoverageProcessor() targeting PhpGitHooks\Module\PhpUn...rictCoverageProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpUn...rageTool::__construct() does only seem to accept object<PhpGitHooks\Modul...rageProcessorInterface>, 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...
33
                $this->getOutputInterface()
34
            )
35
        );
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function itShouldThrowsException()
42
    {
43
        $this->expectException(InvalidStrictCoverageException::class);
44
45
        $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00);
46
        $outputMessage = new PreCommitOutputWriter(StrictCoverageToolHandler::EXECUTE_MESSAGE);
47
48
        $this->shouldWriteOutput($outputMessage->getMessage());
49
        $this->shouldProcessStrictCoverage(0.00);
50
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
51
52
        $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage);
53
        $this->strictCoverageToolCommandHandler->handle($command);
54
    }
55
56
    /**
57
     * @test
58
     */
59 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...
60
    {
61
        $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00);
62
        $outputMessage = new PreCommitOutputWriter(StrictCoverageToolHandler::EXECUTE_MESSAGE);
63
64
        $coverage = 91.00;
65
66
        $this->shouldWriteOutput($outputMessage->getMessage());
67
        $this->shouldProcessStrictCoverage($coverage);
68
        $this->shouldWriteLnOutput(
69
            $this->buildStrictCoverageSuccessfulMessage(
70
                $coverage,
71
                $outputMessage->getSuccessfulMessage()
72
            )
73
        );
74
75
        $command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage);
76
        $this->strictCoverageToolCommandHandler->handle($command);
77
    }
78
79
    private function buildStrictCoverageSuccessfulMessage($coverage, $getSuccessfulMessage)
80
    {
81
        return $getSuccessfulMessage . ' <comment>[' . round($coverage, 0) . '%]</comment>';
82
    }
83
}
84