Completed
Push — master ( e6cd28...033951 )
by Pablo
07:44
created

UnitTestPreCommitExecutor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
ccs 5
cts 5
cp 1
crap 1
1
<?php
2
3
namespace PhpGitHooks\Application\PhpUnit;
4
5
use PhpGitHooks\Application\Config\HookConfigExtraToolInterface;
6
use PhpGitHooks\Application\Config\HookConfigInterface;
7
use PhpGitHooks\Infrastructure\Common\PreCommitExecutor;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class UnitTestPreCommitExecutor extends PreCommitExecutor
11
{
12
    const TOOL = 'phpunit';
13
    const ENABLED_KEY = 'enabled';
14
    const RANDOM_MODE_KEY = 'random-mode';
15
    /** @var PhpUnitHandler */
16
    private $phpunitHandler;
17
    /** @var PhpUnitRandomizerHandler */
18
    private $phpUnitRandomizerHandler;
19
20
    /**
21
     * @param HookConfigInterface      $hookConfigInterface
22
     * @param PhpUnitHandler           $phpUnitHandler
23
     * @param PhpUnitRandomizerHandler $phpUnitRandomizerHandler
24
     */
25 3
    public function __construct(
26
        HookConfigInterface $hookConfigInterface,
27
        PhpUnitHandler $phpUnitHandler,
28
        PhpUnitRandomizerHandler $phpUnitRandomizerHandler
29
    ) {
30 3
        $this->preCommitConfig = $hookConfigInterface;
31 3
        $this->phpunitHandler = $phpUnitHandler;
32 3
        $this->phpUnitRandomizerHandler = $phpUnitRandomizerHandler;
33 3
    }
34
35
    /**
36
     * @param OutputInterface $outputInterface
37
     *
38
     * @throws UnitTestsException
39
     */
40 3
    public function run(OutputInterface $outputInterface)
41
    {
42
        /** @var HookConfigExtraToolInterface $data */
43 3
        $data = $this->preCommitConfig;
44 3
        $extraOptions = $data->extraOptions(PhpUnitConfigData::TOOL);
45 3
        if (true === $extraOptions[self::ENABLED_KEY]) {
46 2
            if (true === $extraOptions[self::RANDOM_MODE_KEY]) {
47
                $this->phpUnitRandomizerHandler->setOutput($outputInterface);
48
                $this->phpUnitRandomizerHandler->run($this->getMessages());
49
            } else {
50 2
                $this->phpunitHandler->setOutput($outputInterface);
51 2
                $this->phpunitHandler->run($this->getMessages());
52
            }
53
        }
54 2
    }
55
56
    /**
57
     * @return string
58
     */
59
    protected function commandName()
60
    {
61
        return self::TOOL;
62
    }
63
}
64