|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2017 Francois-Xavier Soubirou. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of ci-report. |
|
6
|
|
|
* |
|
7
|
|
|
* ci-report is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* ci-report is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with ci-report. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace AppBundle\Entity; |
|
23
|
|
|
|
|
24
|
|
|
use DateTime; |
|
25
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
26
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Suite entity class. |
|
30
|
|
|
* |
|
31
|
|
|
* @category ci-report app |
|
32
|
|
|
* |
|
33
|
|
|
* @author Francois-Xavier Soubirou <[email protected]> |
|
34
|
|
|
* @copyright 2017 Francois-Xavier Soubirou |
|
35
|
|
|
* @license http://www.gnu.org/licenses/ GPLv3 |
|
36
|
|
|
* |
|
37
|
|
|
* @see https://www.ci-report.io |
|
38
|
|
|
* |
|
39
|
|
|
* @ORM\Table(name="cir_suite") |
|
40
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\SuiteRepository") |
|
41
|
|
|
*/ |
|
42
|
|
|
class Suite |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @var int |
|
46
|
|
|
* |
|
47
|
|
|
* @ORM\Column(name="id", type="integer") |
|
48
|
|
|
* @ORM\Id |
|
49
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
50
|
|
|
*/ |
|
51
|
|
|
private $id; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
* |
|
56
|
|
|
* @ORM\Column(name="name", type="string", length=50) |
|
57
|
|
|
*/ |
|
58
|
|
|
private $name; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var int |
|
62
|
|
|
* |
|
63
|
|
|
* @ORM\Column(name="passed", type="integer") |
|
64
|
|
|
*/ |
|
65
|
|
|
private $passed; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var int |
|
69
|
|
|
* |
|
70
|
|
|
* @ORM\Column(name="failed", type="integer") |
|
71
|
|
|
*/ |
|
72
|
|
|
private $failed; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var int |
|
76
|
|
|
* |
|
77
|
|
|
* @ORM\Column(name="errored", type="integer") |
|
78
|
|
|
*/ |
|
79
|
|
|
private $errored; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @var int |
|
83
|
|
|
* |
|
84
|
|
|
* @ORM\Column(name="skipped", type="integer") |
|
85
|
|
|
*/ |
|
86
|
|
|
private $skipped; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @var int |
|
90
|
|
|
* |
|
91
|
|
|
* @ORM\Column(name="disabled", type="integer") |
|
92
|
|
|
*/ |
|
93
|
|
|
private $disabled; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var float |
|
97
|
|
|
* |
|
98
|
|
|
* @ORM\Column(name="duration", type="float") |
|
99
|
|
|
*/ |
|
100
|
|
|
private $duration; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var DateTime |
|
104
|
|
|
* |
|
105
|
|
|
* @ORM\Column(name="datetime_suite", type="datetime") |
|
106
|
|
|
*/ |
|
107
|
|
|
protected $datetimeSuite; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @Gedmo\SortablePosition |
|
111
|
|
|
* @ORM\Column(name="position", type="integer") |
|
112
|
|
|
*/ |
|
113
|
|
|
private $position; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @var Campaign |
|
117
|
|
|
* |
|
118
|
|
|
* @Gedmo\SortableGroup |
|
119
|
|
|
* @ORM\ManyToOne(targetEntity="Campaign") |
|
120
|
|
|
* @ORM\JoinColumn(name="campaign_id", referencedColumnName="id", nullable=false, onDelete="cascade") |
|
121
|
|
|
*/ |
|
122
|
|
|
private $campaign; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Constructor. |
|
126
|
|
|
* |
|
127
|
|
|
* @param Campaign $campaign |
|
128
|
|
|
*/ |
|
129
|
|
|
public function __construct(Campaign $campaign) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->setCampaign($campaign); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get id. |
|
136
|
|
|
* |
|
137
|
|
|
* @return int |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getId(): int |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->id; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Set name. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $name Name |
|
148
|
|
|
* |
|
149
|
|
|
* @return Suite |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setName(string $name): Suite |
|
152
|
|
|
{ |
|
153
|
|
|
$this->name = $name; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get name. |
|
160
|
|
|
* |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getName(): string |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->name; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Set passed tests count. |
|
170
|
|
|
* |
|
171
|
|
|
* @param int $passed Passed tests |
|
172
|
|
|
* |
|
173
|
|
|
* @return Suite |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setpassed(int $passed): Suite |
|
176
|
|
|
{ |
|
177
|
|
|
$this->passed = $passed; |
|
178
|
|
|
|
|
179
|
|
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Get passed tests count. |
|
184
|
|
|
* |
|
185
|
|
|
* @return int |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getPassed(): int |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->passed; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Set failed tests count. |
|
194
|
|
|
* |
|
195
|
|
|
* @param int $failed Failed tests |
|
196
|
|
|
* |
|
197
|
|
|
* @return Suite |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setFailed(int $failed): Suite |
|
200
|
|
|
{ |
|
201
|
|
|
$this->failed = $failed; |
|
202
|
|
|
|
|
203
|
|
|
return $this; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Get failed tests count. |
|
208
|
|
|
* |
|
209
|
|
|
* @return int |
|
210
|
|
|
*/ |
|
211
|
|
|
public function getFailed(): int |
|
212
|
|
|
{ |
|
213
|
|
|
return $this->failed; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Set errored tests count. |
|
218
|
|
|
* |
|
219
|
|
|
* @param int $errored Errored tests |
|
220
|
|
|
* |
|
221
|
|
|
* @return Suite |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setErrored(int $errored): Suite |
|
224
|
|
|
{ |
|
225
|
|
|
$this->errored = $errored; |
|
226
|
|
|
|
|
227
|
|
|
return $this; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Get errored tests count. |
|
232
|
|
|
* |
|
233
|
|
|
* @return int |
|
234
|
|
|
*/ |
|
235
|
|
|
public function getErrored(): int |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->errored; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Set skipped tests count. |
|
242
|
|
|
* |
|
243
|
|
|
* @param int $skipped Skipped tests |
|
244
|
|
|
* |
|
245
|
|
|
* @return Suite |
|
246
|
|
|
*/ |
|
247
|
|
|
public function setSkipped(int $skipped): Suite |
|
248
|
|
|
{ |
|
249
|
|
|
$this->skipped = $skipped; |
|
250
|
|
|
|
|
251
|
|
|
return $this; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Get skipped tests count. |
|
256
|
|
|
* |
|
257
|
|
|
* @return int |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getSkipped(): int |
|
260
|
|
|
{ |
|
261
|
|
|
return $this->skipped; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Set disabled tests count. |
|
266
|
|
|
* |
|
267
|
|
|
* @param int $disabled Disable tests |
|
268
|
|
|
* |
|
269
|
|
|
* @return Suite |
|
270
|
|
|
*/ |
|
271
|
|
|
public function setDisabled(int $disabled): Suite |
|
272
|
|
|
{ |
|
273
|
|
|
$this->disabled = $disabled; |
|
274
|
|
|
|
|
275
|
|
|
return $this; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Get disabled tests count. |
|
280
|
|
|
* |
|
281
|
|
|
* @return int |
|
282
|
|
|
*/ |
|
283
|
|
|
public function getDisabled(): int |
|
284
|
|
|
{ |
|
285
|
|
|
return $this->disabled; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* Set duration of the suite in second. |
|
290
|
|
|
* |
|
291
|
|
|
* @param float $duration Duration |
|
292
|
|
|
* |
|
293
|
|
|
* @return Suite |
|
294
|
|
|
*/ |
|
295
|
|
|
public function setDuration(float $duration): Suite |
|
296
|
|
|
{ |
|
297
|
|
|
$this->duration = $duration; |
|
298
|
|
|
|
|
299
|
|
|
return $this; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* Get duration of the suite in seconds. |
|
304
|
|
|
* |
|
305
|
|
|
* @return float |
|
306
|
|
|
*/ |
|
307
|
|
|
public function getDuration(): float |
|
308
|
|
|
{ |
|
309
|
|
|
return $this->duration; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* Set datetime of suite. |
|
314
|
|
|
* |
|
315
|
|
|
* @param DateTime $datetime DateTime of suite. |
|
316
|
|
|
* |
|
317
|
|
|
* @return Suite |
|
318
|
|
|
*/ |
|
319
|
|
|
public function setDateTimeSuite(DateTime $datetime): Suite |
|
320
|
|
|
{ |
|
321
|
|
|
$this->datetimeSuite = $datetime; |
|
322
|
|
|
|
|
323
|
|
|
return $this; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Get datetime of suite. |
|
328
|
|
|
* |
|
329
|
|
|
* @return DateTime |
|
330
|
|
|
*/ |
|
331
|
|
|
public function getDateTimeSuite(): DateTime |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->datetimeSuite; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* Set order. |
|
338
|
|
|
* |
|
339
|
|
|
* @param int $position The order. |
|
340
|
|
|
* |
|
341
|
|
|
* @return Suite |
|
342
|
|
|
*/ |
|
343
|
|
|
public function setPosition(int $position): Suite |
|
344
|
|
|
{ |
|
345
|
|
|
$this->position = $position; |
|
346
|
|
|
|
|
347
|
|
|
return $this; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* Get position. |
|
352
|
|
|
* |
|
353
|
|
|
* @return int |
|
354
|
|
|
*/ |
|
355
|
|
|
public function getPosition(): int |
|
356
|
|
|
{ |
|
357
|
|
|
return $this->position; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Get reference id. |
|
362
|
|
|
* |
|
363
|
|
|
* @return int |
|
364
|
|
|
*/ |
|
365
|
|
|
public function getRefid(): int |
|
366
|
|
|
{ |
|
367
|
|
|
return $this->position + 1; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* Set campaign. |
|
372
|
|
|
* |
|
373
|
|
|
* @param Campaign $campaign Campaign |
|
374
|
|
|
* |
|
375
|
|
|
* @return Suite |
|
376
|
|
|
*/ |
|
377
|
|
|
public function setCampaign(Campaign $campaign): Suite |
|
378
|
|
|
{ |
|
379
|
|
|
$this->campaign = $campaign; |
|
380
|
|
|
|
|
381
|
|
|
return $this; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* Get campaign. |
|
386
|
|
|
* |
|
387
|
|
|
* @return Campaign |
|
388
|
|
|
*/ |
|
389
|
|
|
public function getCampaign(): Campaign |
|
390
|
|
|
{ |
|
391
|
|
|
return $this->campaign; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* Get enabled tests. |
|
396
|
|
|
* |
|
397
|
|
|
* @return int |
|
398
|
|
|
*/ |
|
399
|
|
|
public function getEnabled(): int |
|
400
|
|
|
{ |
|
401
|
|
|
return $this->passed |
|
402
|
|
|
+ $this->failed |
|
403
|
|
|
+ $this->errored |
|
404
|
|
|
+ $this->skipped; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* Get percentage of successful tests. |
|
409
|
|
|
* |
|
410
|
|
|
* @return float |
|
411
|
|
|
*/ |
|
412
|
|
|
public function getPercentage(): float |
|
413
|
|
|
{ |
|
414
|
|
|
if ($this->getEnabled() > 0) { |
|
415
|
|
|
return round($this->passed / $this->getEnabled() * 100); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
return 0; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Get suite status. |
|
423
|
|
|
* |
|
424
|
|
|
* @return int Status::FAILED|Status::WARNING|Status::SUCCESS |
|
425
|
|
|
*/ |
|
426
|
|
|
public function getStatus(): int |
|
427
|
|
|
{ |
|
428
|
|
|
if ($this->getPercentage() < $this->campaign->getWarning()) { |
|
429
|
|
|
return Status::FAILED; |
|
430
|
|
|
} |
|
431
|
|
|
if ($this->getPercentage() < $this->campaign->getSuccess()) { |
|
432
|
|
|
return Status::WARNING; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
return Status::SUCCESS; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
|