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

PhpCsToolHandlerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
B itShouldThrowsException() 0 29 2
A itShouldWorksFine() 0 22 2
1
<?php
2
3
namespace PhpGitHooks\Module\PhpCs\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\Git\Tests\Stub\FilesCommittedStub;
9
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsTool;
10
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsToolHandler;
11
use PhpGitHooks\Module\PhpCs\Contract\Exception\PhpCsViolationException;
12
use PhpGitHooks\Module\PhpCs\Tests\Infrastructure\PhpCsUnitTestCase;
13
14
class PhpCsToolHandlerTest extends PhpCsUnitTestCase
15
{
16
    /**
17
     * @var PhpCsToolHandler
18
     */
19
    private $phpCsToolCommandHandler;
20
21
    protected function setUp()
22
    {
23
        $this->phpCsToolCommandHandler = new PhpCsToolHandler(
24
            $this->getOutputInterface(),
25
            $this->getPhpCsToolProcessor()
0 ignored issues
show
Bug introduced by
It seems like $this->getPhpCsToolProcessor() targeting PhpGitHooks\Module\PhpCs...getPhpCsToolProcessor() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\PhpCs...lHandler::__construct() does only seem to accept object<PhpGitHooks\Modul...ToolProcessorInterface>, 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(PhpCsViolationException::class);
35
36
        $output = new PreCommitOutputWriter(PhpCsToolHandler::EXECUTE_MESSAGE);
37
        $files = FilesCommittedStub::createOnlyPhpFiles();
38
39
        $this->shouldWriteOutput($output->getMessage());
40
41
        $errorTxt = null;
42
        foreach ($files as $file) {
43
            $error = 'ERROR-';
44
            $this->shouldProcessPhpCsTool($file, 'PSR2', '', $error);
45
            $errorTxt .= $error;
46
        }
47
48
        $this->shouldWriteLnOutput($output->getFailMessage());
49
        $this->shouldWriteLnOutput($output->setError($errorTxt));
50
        $this->shouldWriteLnOutput(BadJobLogoResponse::paint(HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT));
51
52
        $this->phpCsToolCommandHandler->handle(
53
            new PhpCsTool(
54
                $files,
55
                'PSR2',
56
                HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT,
57
                ''
58
            )
59
        );
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function itShouldWorksFine()
66
    {
67
        $output = new PreCommitOutputWriter(PhpCsToolHandler::EXECUTE_MESSAGE);
68
        $files = FilesCommittedStub::createOnlyPhpFiles();
69
70
        $this->shouldWriteOutput($output->getMessage());
71
72
        foreach ($files as $file) {
73
            $this->shouldProcessPhpCsTool($file, 'PSR2', '', null);
74
        }
75
76
        $this->shouldWriteLnOutput($output->getSuccessfulMessage());
77
78
        $this->phpCsToolCommandHandler->handle(
79
            new PhpCsTool(
80
                $files,
81
                'PSR2',
82
                HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT,
83
                ''
84
            )
85
        );
86
    }
87
}
88