Completed
Push — master ( f87faf...b3e46e )
by Pablo
03:15
created

UnitTestPreCommitExecutor::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 15
ccs 11
cts 12
cp 0.9167
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
crap 3.0052
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 1
                $this->phpUnitRandomizerHandler->setOutput($outputInterface);
48 1
                $this->phpUnitRandomizerHandler->run($this->getMessages());
49
            } else {
50 2
                $this->phpunitHandler->setOutput($outputInterface);
51 2
                $this->phpunitHandler->run($this->getMessages());
52
            }
53 1
        }
54 2
    }
55
56
    /**
57
     * @return string
58
     */
59
    protected function commandName()
60
    {
61
        return self::TOOL;
62
    }
63
}
64