Completed
Push — master ( 344091...41b0ff )
by Pablo
04:39
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
    /** @var PhpUnitHandler */
13
    private $phpunitHandler;
14
    /** @var PhpUnitRandomizerHandler */
15
    private $phpUnitRandomizerHandler;
16
17
    /**
18
     * @param HookConfigInterface      $hookConfigInterface
19
     * @param PhpUnitHandler           $phpUnitHandler
20
     * @param PhpUnitRandomizerHandler $phpUnitRandomizerHandler
21
     */
22 3
    public function __construct(
23
        HookConfigInterface $hookConfigInterface,
24
        PhpUnitHandler $phpUnitHandler,
25
        PhpUnitRandomizerHandler $phpUnitRandomizerHandler
26
    ) {
27 3
        $this->preCommitConfig = $hookConfigInterface;
28 3
        $this->phpunitHandler = $phpUnitHandler;
29 3
        $this->phpUnitRandomizerHandler = $phpUnitRandomizerHandler;
30 3
    }
31
32
    /**
33
     * @param OutputInterface $outputInterface
34
     *
35
     * @throws UnitTestsException
36
     */
37 3
    public function run(OutputInterface $outputInterface)
38
    {
39
        /** @var HookConfigExtraToolInterface $data */
40 3
        $data = $this->preCommitConfig;
41 3
        $extraOptions = $data->extraOptions(PhpUnitConfigData::TOOL);
42 3
        if (true === $extraOptions['enabled']) {
43 2
            if (true === $extraOptions['random-mode']) {
44
                $this->phpUnitRandomizerHandler->setOutput($outputInterface);
45
                $this->phpUnitRandomizerHandler->run($this->getMessages());
46
            } else {
47 2
                $this->phpunitHandler->setOutput($outputInterface);
48 2
                $this->phpunitHandler->run($this->getMessages());
49
            }
50 1
        }
51 2
    }
52
53
    /**
54
     * @return string
55
     */
56
    protected function commandName()
57
    {
58
        return 'phpunit';
59
    }
60
}
61