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

PhpUnitToolHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 61
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A itShouldThrowsException() 0 20 1
A itShouldExecuteAndWorksFine() 0 17 1
1
<?php
2
3
namespace PhpGitHooks\Module\PhpUnit\Tests\Behaviour;
4
5
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
6
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
7
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
8
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool;
9
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolHandler;
10
use PhpGitHooks\Module\PhpUnit\Contract\Exception\PhpUnitViolationException;
11
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase;
12
13
class PhpUnitToolHandlerTest extends PhpUnitUnitTestCase
14
{
15
    /**
16
     * @var PhpUnitToolHandler
17
     */
18
    private $phpUnitToolCommandHandler;
19
20
    protected function setUp()
21
    {
22
        $this->phpUnitToolCommandHandler = new PhpUnitToolHandler(
23
            $this->getOutputInterface(),
24
            $this->getPhpUnitProcessor(),
0 ignored issues
show
Bug introduced by
It seems like $this->getPhpUnitProcessor() targeting PhpGitHooks\Module\PhpUn...::getPhpUnitProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpUn...lHandler::__construct() does only seem to accept object<PhpGitHooks\Modul...UnitProcessorInterface>, 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...
25
            $this->getPhpUnitProcessor()
0 ignored issues
show
Bug introduced by
It seems like $this->getPhpUnitProcessor() targeting PhpGitHooks\Module\PhpUn...::getPhpUnitProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpUn...lHandler::__construct() does only seem to accept object<PhpGitHooks\Modul...UnitProcessorInterface>, 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...
26
        );
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public function itShouldThrowsException()
33
    {
34
        $this->expectException(PhpUnitViolationException::class);
35
36
        $options = '--testsuite default';
37
        $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
38
        $outputMessage = new PreCommitOutputWriter(PhpUnitToolHandler::EXECUTING_MESSAGE);
39
40
        $this->shouldWriteLnOutput($outputMessage->getMessage());
41
        $this->shouldProcessPhpUnit($options, false);
42
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage));
43
44
        $this->phpUnitToolCommandHandler->handle(
45
            new PhpUnitTool(
46
                true,
47
                $options,
48
                $errorMessage
49
            )
50
        );
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function itShouldExecuteAndWorksFine()
57
    {
58
        $options = '--testsuite default';
59
        $errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT;
60
        $outputMessage = new PreCommitOutputWriter(PhpUnitToolHandler::EXECUTING_MESSAGE);
61
62
        $this->shouldWriteLnOutput($outputMessage->getMessage());
63
        $this->shouldProcessPhpUnit($options, true);
64
65
        $this->phpUnitToolCommandHandler->handle(
66
            new PhpUnitTool(
67
                true,
68
                $options,
69
                $errorMessage
70
            )
71
        );
72
    }
73
}
74