Completed
Pull Request — master (#37)
by Alessandro
02:23
created

AbstractParaunitProcess::addTestResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
6
use Paraunit\TestResult\TestResultWithAbnormalTermination;
7
8
/**
9
 * Class AbstractParaunitProcess
10
 * @package Paraunit\Process
11
 */
12
abstract class AbstractParaunitProcess implements ParaunitProcessInterface, RetryAwareInterface, ProcessWithResultsInterface
13
{
14
    /** @var int */
15
    protected $retryCount = 0;
16
17
    /** @var bool */
18
    protected $shouldBeRetried = false;
19
20
    /** @var string */
21
    protected $uniqueId;
22
23
    /** @var string */
24
    protected $filename;
25
26
    /** @var PrintableTestResultInterface[] */
27
    protected $testResults;
28
29
    /** @var  bool */
30
    private $waitingForTestResult;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 91
    public function __construct($commandLine, $uniqueId)
36
    {
37 91
        $this->uniqueId = $uniqueId;
38
39 91
        $filename = array();
40 91
        if (preg_match('/[A-z]*\.php/', $commandLine, $filename) === 1) {
41 9
            $this->filename = $filename[0];
42 9
        }
43
44 91
        $this->testResults = array();
45 91
        $this->waitingForTestResult = false;
46 91
    }
47
48
    /**
49
     * @return string
50
     */
51 21
    public function getUniqueId()
52
    {
53 21
        return $this->uniqueId;
54
    }
55
56
    /**
57
     * @return int
58
     */
59 32
    public function getRetryCount()
60
    {
61 32
        return $this->retryCount;
62
    }
63
64
    /**
65
     */
66 4
    public function increaseRetryCount()
67
    {
68 4
        ++$this->retryCount;
69 4
    }
70
71 7
    public function markAsToBeRetried()
72
    {
73 7
        $this->shouldBeRetried = true;
74 7
        $this->testResults = array();
75 7
    }
76
77
    /**
78
     * @return bool
79
     */
80 22
    public function isToBeRetried()
81
    {
82 22
        return $this->shouldBeRetried;
83
    }
84
85
    /**
86
     * @return $this
87
     */
88 3
    public function reset()
89
    {
90 3
        $this->shouldBeRetried = false;
91 3
    }
92
93
    /**
94
     * @return string
95
     */
96 32
    public function getFilename()
97
    {
98 32
        return $this->filename;
99
    }
100
101
    /**
102
     * @return PrintableTestResultInterface[]
103
     */
104 26
    public function getTestResults()
105
    {
106 26
        return $this->testResults;
107
    }
108
109
    /**
110
     * @param PrintableTestResultInterface $testResult
111
     */
112 29
    public function addTestResult(PrintableTestResultInterface $testResult)
113
    {
114 29
        $this->testResults[] = $testResult;
115 29
        $this->waitingForTestResult = false;
116 29
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 18
    public function hasAbnormalTermination()
122
    {
123 18
        return end($this->testResults) instanceof TestResultWithAbnormalTermination;
124
    }
125
126
    /**
127
     * @return bool
128
     */
129 27
    public function isWaitingForTestResult()
130
    {
131 27
        return $this->waitingForTestResult;
132
    }
133
134
    /**
135
     * @param boolean $waitingForTestResult
136
     */
137 28
    public function setWaitingForTestResult($waitingForTestResult)
138
    {
139 28
        $this->waitingForTestResult = (bool) $waitingForTestResult;
140 28
    }
141
}
142