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

CommandLineWithCoverage::getExecutable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Process;
5
6
use Paraunit\Configuration\PHPDbgBinFile;
7
use Paraunit\Configuration\PHPUnitBinFile;
8
use Paraunit\Configuration\PHPUnitConfig;
9
use Paraunit\Configuration\TempFilenameFactory;
10
11
/**
12
 * Class CommandLineWithCoverage
13
 * @package Paraunit\Process
14
 */
15
class CommandLineWithCoverage extends CommandLine
16
{
17
    /** @var PHPDbgBinFile */
18
    private $phpDbgBinFile;
19
20
    /** @var TempFilenameFactory */
21
    private $filenameFactory;
22
23
    /**
24
     * TestCliCommand constructor.
25
     * @param PHPUnitBinFile $phpUnitBin
26
     * @param PHPDbgBinFile $dbgBinFile
27
     * @param TempFilenameFactory $filenameFactory
28
     */
29 6
    public function __construct(
30
        PHPUnitBinFile $phpUnitBin,
31
        PHPDbgBinFile $dbgBinFile,
32
        TempFilenameFactory $filenameFactory
33
    ) {
34 6
        parent::__construct($phpUnitBin);
35
36 6
        $this->phpDbgBinFile = $dbgBinFile;
37 6
        $this->filenameFactory = $filenameFactory;
38
    }
39
40
    /**
41
     * @return string[]
42
     * @throws \RuntimeException
43
     */
44 3
    public function getExecutable(): array
45
    {
46 3
        if ($this->phpDbgBinFile->isAvailable()) {
47 2
            return [$this->phpDbgBinFile->getPhpDbgBin()];
48
        }
49
50 1
        return parent::getExecutable();
51
    }
52
53
    /**
54
     * @param PHPUnitConfig $config
55
     * @return array
56
     * @throws \RuntimeException
57
     */
58 3
    public function getOptions(PHPUnitConfig $config): array
59
    {
60 3
        if (! $this->phpDbgBinFile->isAvailable()) {
61 1
            return parent::getOptions($config);
62
        }
63
64 2
        return array_merge(
65
            [
66 2
                '-qrr',
67 2
                $this->phpUnitBin->getPhpUnitBin()
68
            ],
69 2
            parent::getOptions($config)
70
        );
71
    }
72
73 2
    public function getSpecificOptions(string $testFilename): array
74
    {
75 2
        $options = parent::getSpecificOptions($testFilename);
76 2
        $options[] = '--coverage-php=' . $this->filenameFactory->getFilenameForCoverage(md5($testFilename));
77
78 2
        return $options;
79
    }
80
}
81