|
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
|
|
|
* @param TempFilenameFactory $tempFilenameFactory |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct( |
|
30
|
|
|
CommandLine $cliCommand, |
|
31
|
|
|
PHPUnitConfig $phpunitConfig, |
|
32
|
|
|
TempFilenameFactory $tempFilenameFactory |
|
33
|
|
|
) { |
|
34
|
|
|
$this->cliCommand = $cliCommand; |
|
35
|
|
|
$this->builderPrototype = new ProcessBuilder(); |
|
36
|
|
|
|
|
37
|
|
|
$this->builderPrototype->addEnvironmentVariables([ |
|
38
|
|
|
EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(), |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($this->cliCommand->getExecutable() as $item) { |
|
42
|
|
|
$this->builderPrototype->add($item); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
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
|
|
|
$builder = clone $this->builderPrototype; |
|
53
|
|
|
$builder->add($testFilePath); |
|
54
|
|
|
foreach ($this->cliCommand->getSpecificOptions($testFilePath) as $specificOption) { |
|
55
|
|
|
$builder->add($specificOption); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return new SymfonyProcessWrapper($builder->getProcess(), $testFilePath); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|