Completed
Push — master ( c67234...8b2a99 )
by Pablo
10s
created

buildStrictCoverageSuccessfulMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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\StrictCoverageCommand;
10
use PhpGitHooks\Module\PhpUnit\Contract\CommandHandler\StrictCoverageToolCommandHandler;
11
use PhpGitHooks\Module\PhpUnit\Contract\Exception\InvalidStrictCoverageException;
12
use PhpGitHooks\Module\PhpUnit\Service\StrictCoverageTool;
13
use PhpGitHooks\Module\PhpUnit\Service\StrictCoverageToolExecutor;
14
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase;
15
16
class StrictCoverageToolCommandHandlerTest extends PhpUnitUnitTestCase
17
{
18
    /**
19
     * @var string
20
     */
21
    private $errorMessage;
22
    /**
23
     * @var StrictCoverageToolCommandHandler
24
     */
25
    private $strictCoverageToolCommandHandler;
26
27
    protected function setUp()
28
    {
29
        $this->errorMessage = ConfigArrayDataStub::ERROR_MESSAGE;
30
        $this->strictCoverageToolCommandHandler = new StrictCoverageToolCommandHandler(
31
            new StrictCoverageToolExecutor(
32
                $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\PhpUn...Executor::__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...
33
                new StrictCoverageTool(
34
                    $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...
35
                    $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\PhpUn...rageTool::__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...
36
                )
37
            )
38
        );
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function itShouldThrowsException()
45
    {
46
        $this->expectException(InvalidStrictCoverageException::class);
47
48
        $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00);
49
        $outputMessage = new PreCommitOutputWriter(StrictCoverageToolExecutor::EXECUTE_MESSAGE);
50
51
        $this->shouldWriteOutput($outputMessage->getMessage());
52
        $this->shouldProcessStrictCoverage(0.00);
53
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
54
55
        $command = new StrictCoverageCommand($minimumStrictCoverage->value(), $this->errorMessage);
56
        $this->strictCoverageToolCommandHandler->handle($command);
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
        $minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00);
65
        $outputMessage = new PreCommitOutputWriter(StrictCoverageToolExecutor::EXECUTE_MESSAGE);
66
67
        $coverage = 91.00;
68
69
        $this->shouldWriteOutput($outputMessage->getMessage());
70
        $this->shouldProcessStrictCoverage($coverage);
71
        $this->shouldWriteLnOutput($this->buildStrictCoverageSuccessfulMessage($coverage,
72
            $outputMessage->getSuccessfulMessage()));
73
74
        $command = new StrictCoverageCommand($minimumStrictCoverage->value(), $this->errorMessage);
75
        $this->strictCoverageToolCommandHandler->handle($command);
76
    }
77
78
    private function buildStrictCoverageSuccessfulMessage($coverage, $getSuccessfulMessage)
79
    {
80
        return $getSuccessfulMessage . ' <comment>[' . round($coverage, 0) . '%]</comment>';
81
    }
82
}
83