1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Paraunit\Process; |
5
|
|
|
|
6
|
|
|
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface; |
7
|
|
|
use Paraunit\TestResult\TestResultWithAbnormalTermination; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class AbstractParaunitProcess |
11
|
|
|
* @package Paraunit\Process |
12
|
|
|
*/ |
13
|
|
|
abstract class AbstractParaunitProcess |
14
|
|
|
{ |
15
|
|
|
/** @var int */ |
16
|
|
|
protected $retryCount = 0; |
17
|
|
|
|
18
|
|
|
/** @var bool */ |
19
|
|
|
protected $shouldBeRetried; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $uniqueId; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
protected $filename; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
protected $testClassName; |
29
|
|
|
|
30
|
|
|
/** @var PrintableTestResultInterface[] */ |
31
|
|
|
protected $testResults; |
32
|
|
|
|
33
|
|
|
/** @var bool */ |
34
|
|
|
private $waitingForTestResult; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
* @throws \InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
|
public function __construct(string $filename) |
41
|
|
|
{ |
42
|
|
|
$this->filename = $filename; |
43
|
|
|
$this->uniqueId = md5($this->filename); |
44
|
|
|
$this->testResults = []; |
45
|
|
|
$this->waitingForTestResult = true; |
46
|
|
|
$this->shouldBeRetried = false; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
abstract public function getOutput(): string; |
50
|
|
|
|
51
|
|
|
abstract public function isTerminated(): bool; |
52
|
|
|
|
53
|
|
|
abstract public function getCommandLine(): string; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return int|null |
57
|
|
|
*/ |
58
|
|
|
abstract public function getExitCode(); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param array $env An array of environment variables to be injected |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
abstract public function start(array $env = []); |
65
|
|
|
|
66
|
|
|
public function getUniqueId(): string |
67
|
|
|
{ |
68
|
|
|
return $this->uniqueId; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getRetryCount(): int |
72
|
|
|
{ |
73
|
|
|
return $this->retryCount; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function increaseRetryCount() |
77
|
|
|
{ |
78
|
|
|
++$this->retryCount; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function markAsToBeRetried() |
82
|
|
|
{ |
83
|
|
|
$this->shouldBeRetried = true; |
84
|
|
|
$this->testResults = []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function isToBeRetried(): bool |
88
|
|
|
{ |
89
|
|
|
return $this->shouldBeRetried; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function reset() |
93
|
|
|
{ |
94
|
|
|
$this->shouldBeRetried = false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getFilename(): string |
98
|
|
|
{ |
99
|
|
|
return $this->filename; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string|null |
104
|
|
|
*/ |
105
|
|
|
public function getTestClassName() |
106
|
|
|
{ |
107
|
|
|
return $this->testClassName; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function setTestClassName(string $testClassName) |
111
|
|
|
{ |
112
|
|
|
$this->testClassName = $testClassName; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return PrintableTestResultInterface[] |
117
|
|
|
*/ |
118
|
|
|
public function getTestResults(): array |
119
|
|
|
{ |
120
|
|
|
return $this->testResults; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function addTestResult(PrintableTestResultInterface $testResult) |
124
|
|
|
{ |
125
|
|
|
$this->testResults[] = $testResult; |
126
|
|
|
$this->waitingForTestResult = false; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function hasAbnormalTermination(): bool |
130
|
|
|
{ |
131
|
|
|
return end($this->testResults) instanceof TestResultWithAbnormalTermination; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function isWaitingForTestResult(): bool |
135
|
|
|
{ |
136
|
|
|
return $this->waitingForTestResult; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setWaitingForTestResult(bool $waitingForTestResult) |
140
|
|
|
{ |
141
|
|
|
$this->waitingForTestResult = (bool)$waitingForTestResult; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|