Completed
Pull Request — master (#94)
by Alessandro
04:33
created

CommandLine::buildPhpunitOptionString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\Configuration\PHPUnitBinFile;
6
use Paraunit\Configuration\PHPUnitConfig;
7
use Paraunit\Configuration\PHPUnitOption;
8
use Paraunit\Parser\JSON\LogPrinter;
9
10
/**
11
 * Class TestCliCommand
12
 * @package Paraunit\Process
13
 */
14
class CommandLine
15
{
16
    /** @var  PHPUnitBinFile */
17
    protected $phpUnitBin;
18
19
    /**
20
     * TestCliCommand constructor.
21
     * @param PHPUnitBinFile $phpUnitBin
22
     */
23 36
    public function __construct(PHPUnitBinFile $phpUnitBin)
24
    {
25 36
        $this->phpUnitBin = $phpUnitBin;
26
    }
27
28
    /**
29
     * @return string[]
30
     */
31 30
    public function getExecutable(): array
32
    {
33 30
        return ['php', $this->phpUnitBin->getPhpUnitBin()];
34
    }
35
36
    /**
37
     * @param PHPUnitConfig $config
38
     * @return array
39
     * @throws \RuntimeException When the config handling fails
40
     */
41 32
    public function getOptions(PHPUnitConfig $config): array
42
    {
43
        $options = [
44 32
            '--configuration=' . $config->getFileFullPath(),
45
            '--printer=' . LogPrinter::class,
46
        ];
47
48 32
        foreach ($config->getPhpunitOptions() as $phpunitOption) {
49 6
            $options[] = $this->buildPhpunitOptionString($phpunitOption);
50
        }
51
52 32
        return $options;
53
    }
54
55 6
    private function buildPhpunitOptionString(PHPUnitOption $option): string
56
    {
57 6
        $optionString = '--' . $option->getName();
58 6
        if ($option->hasValue()) {
59 5
            $optionString .= '=' . $option->getValue();
60
        }
61
62 6
        return $optionString;
63
    }
64
65 16
    public function getSpecificOptions(string $testFilename): array
66
    {
67 16
        return [];
68
    }
69
}
70