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

ProcessBuilderFactory::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 12
nc 4
nop 3
crap 3
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\Configuration\EnvVariables;
6
use Paraunit\Configuration\PHPUnitConfig;
7
use Paraunit\Configuration\TempFilenameFactory;
8
use Symfony\Component\Process\ProcessBuilder;
9
10
/**
11
 * Class ProcessBuilderFactory
12
 * @package Paraunit\Process
13
 */
14
class ProcessBuilderFactory
15
{
16
    /** @var ProcessBuilder */
17
    private $builderPrototype;
18
    /** @var CommandLine */
19
    private $cliCommand;
20
21
    /**
22
     * ProcessBuilderFactory constructor.
23
     * @param CommandLine $cliCommand
24
     * @param PHPUnitConfig $phpunitConfig
25
     * @param TempFilenameFactory $tempFilenameFactory
26
     */
27 30
    public function __construct(
28
        CommandLine $cliCommand,
29
        PHPUnitConfig $phpunitConfig,
30
        TempFilenameFactory $tempFilenameFactory
31
    ) {
32 30
        $this->cliCommand = $cliCommand;
33 30
        $this->builderPrototype = new ProcessBuilder();
34
35 30
        $this->builderPrototype->addEnvironmentVariables([
36 30
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
37
        ]);
38
39 30
        foreach ($this->cliCommand->getExecutable() as $item) {
40 30
            $this->builderPrototype->add($item);
41
        }
42
43 30
        foreach ($this->cliCommand->getOptions($phpunitConfig) as $option) {
44 30
            $this->builderPrototype->add($option);
45
        }
46
    }
47
48
    /**
49
     * @param $testFilePath
50
     * @return ProcessBuilder
51
     */
52 16
    public function create(string $testFilePath): ProcessBuilder
53
    {
54 16
        $builder = clone $this->builderPrototype;
55 16
        $builder->add($testFilePath);
56 16
        foreach ($this->cliCommand->getSpecificOptions($testFilePath) as $specificOption) {
57 2
            $builder->add($specificOption);
58
        }
59
60 16
        return $builder;
61
    }
62
}
63