Completed
Pull Request — master (#59)
by Alessandro
05:25
created

ProcessFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\Configuration\PHPUnitConfig;
6
7
/**
8
 * Class ProcessFactory
9
 * @package Paraunit\Process
10
 */
11
class ProcessFactory
12
{
13
    /** @var  CliCommandInterface */
14
    private $cliCommand;
15
16
    /** @var  PHPUnitConfig */
17
    private $phpunitConfig;
18
19
    /**
20
     * ProcessFactory constructor.
21
     * @param CliCommandInterface $cliCommand
22
     */
23 11
    public function __construct(CliCommandInterface $cliCommand)
24
    {
25 11
        $this->cliCommand = $cliCommand;
26 11
    }
27
28
    /**
29
     * @param $testFilePath
30
     * @return SymfonyProcessWrapper
31
     * @throws \Exception
32
     */
33 11
    public function createProcess($testFilePath)
34
    {
35 11
        $uniqueId = $this->createUniqueId($testFilePath);
36 11
        $command = $this->createCommandLine($testFilePath, $uniqueId);
37
38 11
        return new SymfonyProcessWrapper($command, $uniqueId);
39
    }
40
41
    /**
42
     * @param string $testFilePath
43
     * @param string $uniqueId
44
     * @return string
45
     */
46 11
    private function createCommandLine($testFilePath, $uniqueId)
47
    {
48 11
        return $this->cliCommand->getExecutable()
49 11
            . ' ' . $this->cliCommand->getOptions($this->phpunitConfig, $uniqueId)
50 11
            . ' ' . $testFilePath;
51
    }
52
53
    /**
54
     * @param string $testFilePath
55
     * @return string
56
     */
57 11
    private function createUniqueId($testFilePath)
58
    {
59 11
        return md5($testFilePath);
60
    }
61
62 11
    public function setPHPUnitConfig(PHPUnitConfig $phpunitConfig)
63
    {
64 11
        $this->phpunitConfig = $phpunitConfig;
65 11
    }
66
}
67