Completed
Pull Request — master (#59)
by Alessandro
05:30
created

TestCommandLine::getExecutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\Configuration\PHPUnitBinFile;
6
use Paraunit\Configuration\PHPUnitConfig;
7
use Paraunit\Configuration\TempFilenameFactory;
8
9
/**
10
 * Class TestCliCommand
11
 * @package Paraunit\Process
12
 */
13
class TestCommandLine implements CliCommandInterface
14
{
15
    /** @var  PHPUnitBinFile */
16
    private $phpUnitBin;
17
18
    /** @var  TempFilenameFactory */
19
    protected $filenameFactory;
20
21
    /**
22
     * TestCliCommand constructor.
23
     * @param PHPUnitBinFile $phpUnitBin
24
     * @param TempFilenameFactory $filenameFactory
25
     */
26 16
    public function __construct(PHPUnitBinFile $phpUnitBin, TempFilenameFactory $filenameFactory)
27
    {
28 16
        $this->phpUnitBin = $phpUnitBin;
29 16
        $this->filenameFactory = $filenameFactory;
30 16
    }
31
32
    /**
33
     * @return string
34
     */
35 13
    public function getExecutable()
36
    {
37 13
        return $this->phpUnitBin->getPhpUnitBin();
38
    }
39
40
    /**
41
     * @param PHPUnitConfig $config
42
     * @param string $uniqueId
43
     * @return string
44
     */
45 13
    public function getOptions(PHPUnitConfig $config, $uniqueId)
46
    {
47 13
        return '-c ' . $config->getFileFullPath()
48 13
            . ' --log-json ' . $this->filenameFactory->getFilenameForLog($uniqueId)
49 13
            . $this->createOptionsString($config);
50
    }
51
52 13
    private function createOptionsString(PHPUnitConfig $config)
53
    {
54 13
        $optionString = '';
55
56 13
        foreach ($config->getPhpunitOptions() as $option) {
57 3
            $optionString .= ' --' . $option->getName();
58 3
            if ($option->hasValue()) {
59 3
                $optionString .= '=' . $option->getValue();
60 3
            }
61 13
        }
62
        
63 13
        return $optionString;
64
    }
65
}
66