Completed
Push — master ( 9a7b87...ad20a3 )
by Alessandro
03:07
created

AbstractParaunitProcess::hasAbnormalTermination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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