Completed
Push — master ( deb1d5...3324ab )
by Pablo
04:13
created

Tests/Behaviour/PreCommitProcessorTest.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Tests\Behaviour;
4
5
use Composer\IO\IOInterface;
6
use PhpGitHooks\Module\Configuration\Domain\Execute;
7
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
8
use PhpGitHooks\Module\Configuration\Domain\PhpUnitStrictCoverage;
9
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
10
use PhpGitHooks\Module\Configuration\Service\PhpGuardCoverageGitIgnoreConfigurator;
11
use PhpGitHooks\Module\Configuration\Service\PhpUnitGuardCoverageConfigurator;
12
use PhpGitHooks\Module\Configuration\Service\PreCommitProcessor;
13
use PhpGitHooks\Module\Configuration\Tests\Infrastructure\ConfigurationUnitTestCase;
14
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitStub;
15
16
class PreCommitProcessorTest extends ConfigurationUnitTestCase
17
{
18
    /**
19
     * @var PreCommitProcessor
20
     */
21
    private $preCommitProcessor;
22
    /**
23
     * @var IOInterface
24
     */
25
    private $io;
26
27
    protected function setUp()
28
    {
29
        $this->io = $this->getIOInterface();
30
        $this->preCommitProcessor = new PreCommitProcessor(
31
            new PhpUnitGuardCoverageConfigurator(
32
                new PhpGuardCoverageGitIgnoreConfigurator(
33
                    $this->getQueryBus(),
0 ignored issues
show
It seems like $this->getQueryBus() targeting PhpGitHooks\Module\Share...BusTrait::getQueryBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...dBus\QueryBus\QueryBus>, 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...
34
                    $this->getCommandBus()
0 ignored issues
show
It seems like $this->getCommandBus() targeting PhpGitHooks\Module\Share...sTrait::getCommandBus() can also be of type object<Mockery\MockInterface>; however, PhpGitHooks\Module\Confi...igurator::__construct() does only seem to accept object<PhpGitHooks\Infra...\CommandBus\CommandBus>, 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
                )
36
            )
37
        );
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function itShouldDisablePreCommitHook()
44
    {
45
        $this->shouldAsk(HookQuestions::PRE_COMMIT_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER, 'n');
46
47
        $preCommitData = $this->preCommitProcessor->process(PreCommitStub::createUndefined(), $this->io);
48
49
        $this->assertFalse($preCommitData->isEnabled());
50
        $this->assertFalse($preCommitData->isUndefined());
51
        $this->assertNull($preCommitData->getMessages()->getRightMessage()->value());
52
        $this->assertNull($preCommitData->getMessages()->getErrorMessage()->value());
53
54
        /** @var Execute $execute */
55
        $execute = $preCommitData->getExecute();
56
        $tools = $execute->execute();
57
58
        $composer = $tools[0];
59
        $jsonLint = $tools[1];
60
        $phpLint = $tools[2];
61
        /** @var PhpUnitStrictCoverage $phpunitStrictCoverage */
62
        $phpunitStrictCoverage = $tools[7];
63
64
        $this->assertFalse($composer->isEnabled());
65
        $this->assertFalse($composer->isUndefined());
66
        $this->assertFalse($jsonLint->isEnabled());
67
        $this->assertFalse($jsonLint->isUndefined());
68
        $this->assertFalse($phpLint->isEnabled());
69
        $this->assertFalse($phpLint->isUndefined());
70
        $this->assertFalse($phpunitStrictCoverage->isUndefined());
71
    }
72
}
73