Completed
Pull Request — master (#94)
by Alessandro
08:53
created

CommandLine::buildPhpunitOptionString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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
    public function __construct(PHPUnitBinFile $phpUnitBin)
24
    {
25
        $this->phpUnitBin = $phpUnitBin;
26
    }
27
28
    /**
29
     * @return string[]
30
     */
31
    public function getExecutable(): array
32
    {
33
        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
    public function getOptions(PHPUnitConfig $config): array
42
    {
43
        $options = [
44
            '--configuration=' . $config->getFileFullPath(),
45
            '--printer=' . LogPrinter::class,
46
        ];
47
48
        foreach ($config->getPhpunitOptions() as $phpunitOption) {
49
            $options[] = $this->buildPhpunitOptionString($phpunitOption);
50
        }
51
52
        return $options;
53
    }
54
55
    private function buildPhpunitOptionString(PHPUnitOption $option): string
56
    {
57
        $optionString = '--' . $option->getName();
58
        if ($option->hasValue()) {
59
            $optionString .= '=' . $option->getValue();
60
        }
61
62
        return $optionString;
63
    }
64
65
    public function getSpecificOptions(string $testFilename): array
66
    {
67
        return [];
68
    }
69
}
70