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

ProcessBuilderFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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
    public function __construct(
28
        CommandLine $cliCommand,
29
        PHPUnitConfig $phpunitConfig,
30
        TempFilenameFactory $tempFilenameFactory
31
    ) {
32
        $this->cliCommand = $cliCommand;
33
        $this->builderPrototype = new ProcessBuilder();
34
35
        $this->builderPrototype->addEnvironmentVariables([
36
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
37
        ]);
38
39
        foreach ($this->cliCommand->getExecutable() as $item) {
40
            $this->builderPrototype->add($item);
41
        }
42
43
        foreach ($this->cliCommand->getOptions($phpunitConfig) as $option) {
44
            $this->builderPrototype->add($option);
45
        }
46
    }
47
48
    /**
49
     * @param $testFilePath
50
     * @return ProcessBuilder
51
     */
52
    public function create(string $testFilePath): ProcessBuilder
53
    {
54
        $builder = clone $this->builderPrototype;
55
        $builder->add($testFilePath);
56
        foreach ($this->cliCommand->getSpecificOptions($testFilePath) as $specificOption) {
57
            $builder->add($specificOption);
58
        }
59
60
        return $builder;
61
    }
62
}
63