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