|
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 implements ParaunitProcessInterface, RetryAwareInterface, ProcessWithResultsInterface |
|
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
|
109 |
|
public function __construct(string $filePath, string $uniqueId) |
|
41
|
|
|
{ |
|
42
|
109 |
|
$filename = []; |
|
43
|
109 |
|
if (preg_match('~([^\\\\/]+)$~', $filePath, $filename) === 1) { |
|
44
|
109 |
|
$this->filename = $filename[1]; |
|
45
|
|
|
} else { |
|
46
|
|
|
throw new \InvalidArgumentException('Filename not recognized: ' . $filePath); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
109 |
|
$this->uniqueId = $uniqueId; |
|
50
|
|
|
|
|
51
|
109 |
|
$this->shouldBeRetried = false; |
|
52
|
109 |
|
$this->testResults = []; |
|
53
|
109 |
|
$this->waitingForTestResult = true; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
40 |
|
public function getUniqueId(): string |
|
57
|
|
|
{ |
|
58
|
40 |
|
return $this->uniqueId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
37 |
|
public function getRetryCount(): int |
|
62
|
|
|
{ |
|
63
|
37 |
|
return $this->retryCount; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
6 |
|
public function increaseRetryCount() |
|
67
|
|
|
{ |
|
68
|
6 |
|
++$this->retryCount; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
9 |
|
public function markAsToBeRetried() |
|
72
|
|
|
{ |
|
73
|
9 |
|
$this->shouldBeRetried = true; |
|
74
|
9 |
|
$this->testResults = []; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
30 |
|
public function isToBeRetried(): bool |
|
78
|
|
|
{ |
|
79
|
30 |
|
return $this->shouldBeRetried; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
5 |
|
public function reset() |
|
83
|
|
|
{ |
|
84
|
5 |
|
$this->shouldBeRetried = false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
22 |
|
public function getFilename(): string |
|
88
|
|
|
{ |
|
89
|
22 |
|
return $this->filename; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string|null |
|
94
|
|
|
*/ |
|
95
|
38 |
|
public function getTestClassName() |
|
96
|
|
|
{ |
|
97
|
38 |
|
return $this->testClassName; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
25 |
|
public function setTestClassName(string $testClassName) |
|
101
|
|
|
{ |
|
102
|
25 |
|
$this->testClassName = $testClassName; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return PrintableTestResultInterface[] |
|
107
|
|
|
*/ |
|
108
|
35 |
|
public function getTestResults(): array |
|
109
|
|
|
{ |
|
110
|
35 |
|
return $this->testResults; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
39 |
|
public function addTestResult(PrintableTestResultInterface $testResult) |
|
114
|
|
|
{ |
|
115
|
39 |
|
$this->testResults[] = $testResult; |
|
116
|
39 |
|
$this->waitingForTestResult = false; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
19 |
|
public function hasAbnormalTermination(): bool |
|
120
|
|
|
{ |
|
121
|
19 |
|
return end($this->testResults) instanceof TestResultWithAbnormalTermination; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
35 |
|
public function isWaitingForTestResult(): bool |
|
125
|
|
|
{ |
|
126
|
35 |
|
return $this->waitingForTestResult; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
34 |
|
public function setWaitingForTestResult(bool $waitingForTestResult) |
|
130
|
|
|
{ |
|
131
|
34 |
|
$this->waitingForTestResult = (bool)$waitingForTestResult; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|