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

PhpUnitToolHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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