Completed
Pull Request — master (#112)
by Alessandro
05:50
created

ProcessBuilderFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Process;
6
7
use Paraunit\Configuration\EnvVariables;
8
use Paraunit\Configuration\PHPUnitConfig;
9
use Paraunit\Configuration\TempFilenameFactory;
10
use Symfony\Component\Process\ProcessBuilder;
11
12
/**
13
 * Class ProcessBuilderFactory
14
 * @package Paraunit\Process
15
 */
16
class ProcessBuilderFactory implements ProcessFactoryInterface
17
{
18
    /** @var ProcessBuilder */
19
    private $builderPrototype;
20
    /** @var CommandLine */
21
    private $cliCommand;
22
23
    /**
24
     * ProcessBuilderFactory constructor.
25
     * @param CommandLine $cliCommand
26
     * @param PHPUnitConfig $phpunitConfig
27 35
     * @param TempFilenameFactory $tempFilenameFactory
28
     */
29
    public function __construct(
30
        CommandLine $cliCommand,
31
        PHPUnitConfig $phpunitConfig,
32 35
        TempFilenameFactory $tempFilenameFactory
33 35
    ) {
34
        $this->cliCommand = $cliCommand;
35 35
        $this->builderPrototype = new ProcessBuilder();
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Process\ProcessBuilder has been deprecated with message: since version 3.4, to be removed in 4.0. Use the Process class instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36 35
37
        $this->builderPrototype->addEnvironmentVariables([
38
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
39 35
        ]);
40 35
41
        foreach ($this->cliCommand->getExecutable() as $item) {
42
            $this->builderPrototype->add($item);
43 35
        }
44 35
45
        foreach ($this->cliCommand->getOptions($phpunitConfig) as $option) {
46
            $this->builderPrototype->add($option);
47
        }
48
    }
49
50
    public function create(string $testFilePath): AbstractParaunitProcess
51
    {
52 19
        $builder = clone $this->builderPrototype;
53
        $builder->add($testFilePath);
54 19
        foreach ($this->cliCommand->getSpecificOptions($testFilePath) as $specificOption) {
55 19
            $builder->add($specificOption);
56 19
        }
57 2
58
        return new SymfonyProcessWrapper($builder->getProcess(), $testFilePath);
59
    }
60
}
61