Completed
Push — master ( 11aa12...25ec1c )
by Erin
01:41
created

TestResult::setIsFocusedByDsl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Peridot\Core;
4
5
use Evenement\EventEmitterInterface;
6
7
/**
8
 * TestResults tracks passing, pending, and failing tests.
9
 *
10
 * @package Peridot\Core
11
 */
12
class TestResult
13
{
14
    use HasEventEmitterTrait;
15
16
    /**
17
     * Tracks total tests run against this result
18
     *
19
     * @var int
20
     */
21
    protected $testCount = 0;
22
23
    /**
24
     * Tracks total number of failed tests run against this result
25
     *
26
     * @var int
27
     */
28
    protected $failureCount = 0;
29
30
    /**
31
     * Tracks total number of pending tests run against this result
32
     *
33
     * @var int
34
     */
35
    protected $pendingCount = 0;
36
37
    /**
38
     * True if focused specs were configured via DSL functions
39
     *
40
     * @var bool
41
     */
42
    protected $isFocusedByDsl = false;
43
44
    /**
45
     * @param EventEmitterInterface $eventEmitter
46
     */
47
    public function __construct(EventEmitterInterface $eventEmitter)
48
    {
49
        $this->eventEmitter = $eventEmitter;
50
    }
51
52
    /**
53
     * Returns a summary string containing total tests run and total tests
54
     * failed
55
     *
56
     * @return string
57
     */
58
    public function getSummary()
59
    {
60
        $summary = sprintf('%d run, %d failed', $this->testCount, $this->failureCount);
61
        if ($this->pendingCount > 0) {
62
            $summary .= sprintf(', %d pending', $this->pendingCount);
63
        }
64
65
        return $summary;
66
    }
67
68
    /**
69
     * Fail the given test.
70
     *
71
     * @param TestInterface $test
72
     * @param mixed $exception
73
     */
74
    public function failTest(TestInterface $test, $exception)
75
    {
76
        $this->failureCount++;
77
        $this->eventEmitter->emit('test.failed', [$test, $exception]);
78
    }
79
80
    /**
81
     * Notify result that test is pending
82
     *
83
     * @param TestInterface $test
84
     */
85
    public function pendTest(TestInterface $test)
86
    {
87
        $this->pendingCount++;
88
        $this->eventEmitter->emit('test.pending', [$test]);
89
    }
90
91
    /**
92
     * Pass the given test.
93
     *
94
     * @param TestInterface $test
95
     */
96
    public function passTest(TestInterface $test)
97
    {
98
        $this->eventEmitter->emit('test.passed', [$test]);
99
    }
100
101
    /**
102
     * Increment test count and emit start event
103
     *
104
     * @param TestInterface $test
105
     */
106
    public function startTest(TestInterface $test)
107
    {
108
        $this->testCount++;
109
        $this->eventEmitter->emit('test.start', [$test]);
110
    }
111
112
    /**
113
     * Emit end event for a test
114
     *
115
     * @param TestInterface $test
116
     */
117
    public function endTest(TestInterface $test)
118
    {
119
        $this->eventEmitter->emit('test.end', [$test]);
120
    }
121
122
    /**
123
     * Get the number of failures tracked by this result.
124
     *
125
     * @return int
126
     */
127
    public function getFailureCount()
128
    {
129
        return $this->failureCount;
130
    }
131
132
    /**
133
     * Set the number of failures tracked by this result.
134
     *
135
     * @param int $failureCount
136
     */
137
    public function setFailureCount($failureCount)
138
    {
139
        $this->failureCount = $failureCount;
140
        return $this;
141
    }
142
143
    /**
144
     * Get the number of tests tracked by this
145
     * result.
146
     *
147
     * @return int
148
     */
149
    public function getTestCount()
150
    {
151
        return $this->testCount;
152
    }
153
154
    /**
155
     * Set the number of tests tracked by this
156
     * result.
157
     *
158
     * @param int $testCount
159
     */
160
    public function setTestCount($testCount)
161
    {
162
        $this->testCount = $testCount;
163
        return $this;
164
    }
165
166
    /**
167
     * Get the number of pending tests tracked
168
     * by this test result.
169
     *
170
     * @return int
171
     */
172
    public function getPendingCount()
173
    {
174
        return $this->pendingCount;
175
    }
176
177
    /**
178
     * Set the number of pending tests tracked
179
     * by this test result.
180
     *
181
     * @param int $pendingCount
182
     */
183
    public function setPendingCount($pendingCount)
184
    {
185
        $this->pendingCount = $pendingCount;
186
        return $this;
187
    }
188
189
    /**
190
     * Returns true if focused specs were configured via DSL functions
191
     *
192
     * @return bool
193
     */
194
    public function isFocusedByDsl()
195
    {
196
        return $this->isFocusedByDsl;
197
    }
198
199
    /**
200
     * Mark this result as having focused specs configured via DSL functions
201
     *
202
     * @param bool $isFocusedByDsl
203
     */
204
    public function setIsFocusedByDsl($isFocusedByDsl)
205
    {
206
        $this->isFocusedByDsl = $isFocusedByDsl;
207
        return $this;
208
    }
209
}
210