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

StrictCoverageToolHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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