Completed
Push — output_parsers_refactor ( cf2136...710907 )
by Alessandro
02:32
created

ProcessFactory::createUniqueId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
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\PHPUnitBinFile;
6
use Paraunit\Configuration\PHPUnitConfigFile;
7
8
/**
9
 * Class ProcessFactory
10
 * @package Paraunit\Process
11
 */
12
class ProcessFactory
13
{
14
    /** @var  string */
15
    private $phpUnitBin;
16
17
    /** @var  PHPUnitConfigFile */
18
    private $phpunitConfigFile;
19
20
    /**
21
     * ProcessFactory constructor.
22
     * @param PHPUnitBinFile $phpUnitBinFile
23
     */
24 9
    public function __construct(PHPUnitBinFile $phpUnitBinFile)
25
    {
26 9
        $this->phpUnitBin = $phpUnitBinFile->getPhpUnitBin();
27 9
    }
28
29
    /**
30
     * @param $testFilePath
31
     * @return SymfonyProcessWrapper
32
     * @throws \Exception
33
     */
34 9
    public function createProcess($testFilePath)
35
    {
36 9
        if ( ! $this->phpunitConfigFile instanceof PHPUnitConfigFile) {
37 1
            throw new \Exception('PHPUnit config missing');
38
        }
39
40 8
        $uniqueId = $this->createUniqueId($testFilePath);
41 8
        $command = $this->createCommandLine($testFilePath, $uniqueId);
42
43 8
        return new SymfonyProcessWrapper($command, $uniqueId);
44
    }
45
46
    /**
47
     * @param PHPUnitConfigFile $configFile
48
     */
49 8
    public function setConfigFile(PHPUnitConfigFile $configFile)
50
    {
51 8
        $this->phpunitConfigFile = $configFile;
52 8
    }
53
54
    /**
55
     * @param string $testFilePath
56
     * @param string $uniqueId
57
     * @return string
58
     *
59
     * @todo Separate with appends and prepends, maybe in multiple dedicate classes;
60
     *       we will need it for PHP7 code coverage with PHPDbg
61
     */
62 8
    private function createCommandLine($testFilePath, $uniqueId)
63
    {
64 8
        return $this->phpUnitBin .
65 8
        ' -c ' . $this->phpunitConfigFile->getFileFullPath() .
66 8
        ' --colors=never' .
67 8
        ' --log-json=/dev/shm/paraunit/logs/' . $uniqueId . '.json.log' .
68 8
        ' ' . $testFilePath .
69 8
        ' 2>&1';
70
    }
71
72
    /**
73
     * @param string $testFilePath
74
     * @return string
75
     */
76 8
    private function createUniqueId($testFilePath)
77
    {
78 8
        return md5($testFilePath);
79
    }
80
}
81