Passed
Push — master ( 31593e...785a7b )
by FX
03:35
created

Suite::setDuration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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
use JMS\Serializer\Annotation as Serializer;
28
use Symfony\Component\Validator\Constraints as Assert;
29
30
/**
31
 * Suite entity class.
32
 *
33
 * @category  ci-report app
34
 *
35
 * @author    Francois-Xavier Soubirou <[email protected]>
36
 * @copyright 2017 Francois-Xavier Soubirou
37
 * @license   http://www.gnu.org/licenses/   GPLv3
38
 *
39
 * @see      https://www.ci-report.io
40
 *
41
 * @ORM\Table(name="cir_suite")
42
 * @ORM\Entity(repositoryClass="AppBundle\Repository\SuiteRepository")
43
 */
44
class Suite
45
{
46
    /**
47
     * @var int
48
     *
49
     * @ORM\Column(name="id", type="integer")
50
     * @ORM\Id
51
     * @ORM\GeneratedValue(strategy="AUTO")
52
     *
53
     * @Serializer\Exclude
54
     */
55
    private $id;
56
57
    /**
58
     * Name of the suite.
59
     *
60
     * @var string
61
     *
62
     * @ORM\Column(name="name", type="string", length=50)
63
     *
64
     * @Serializer\Groups({"public", "private"})
65
     */
66
    private $name;
67
68
    /**
69
     * Total number of passed tests.
70
     *
71
     * @var int
72
     *
73
     * @ORM\Column(name="passed", type="integer")
74
     *
75
     * @Assert\NotBlank()
76
     * @Assert\Type("integer")
77
     *
78
     * @Serializer\Groups({"public", "private"})
79
     */
80
    private $passed = 0;
81
82
    /**
83
     * Total number of disabled tests.
84
     *
85
     * @var int
86
     *
87
     * @ORM\Column(name="failed", type="integer")
88
     *
89
     * @Assert\NotBlank()
90
     * @Assert\Type("integer")
91
     *
92
     * @Serializer\Groups({"public", "private"})
93
     */
94
    private $failed = 0;
95
96
    /**
97
     * Total number of errored tests.
98
     *
99
     * @var int
100
     *
101
     * @ORM\Column(name="errored", type="integer")
102
     *
103
     * @Assert\NotBlank()
104
     * @Assert\Type("integer")
105
     *
106
     * @Serializer\Groups({"public", "private"})
107
     */
108
    private $errored = 0;
109
110
    /**
111
     * Total number of skipped tests.
112
     *
113
     * @var int
114
     *
115
     * @ORM\Column(name="skipped", type="integer")
116
     *
117
     * @Assert\NotBlank()
118
     * @Assert\Type("integer")
119
     *
120
     * @Serializer\Groups({"public", "private"})
121
     */
122
    private $skipped = 0;
123
124
    /**
125
     * Total number of disabled tests.
126
     *
127
     * @var int
128
     *
129
     * @ORM\Column(name="disabled", type="integer")
130
     *
131
     * @Assert\NotBlank()
132
     * @Assert\Type("integer")
133
     *
134
     * @Serializer\Groups({"public", "private"})
135
     */
136
    private $disabled = 0;
137
138
    /**
139
     * Duration of the suite in seconds.
140
     *
141
     * @var float
142
     *
143
     * @ORM\Column(name="duration", type="float")
144
     *
145
     * @Assert\NotBlank()
146
     * @Assert\Type("float")
147
     *
148
     * @Serializer\Groups({"public", "private"})
149
     */
150
    private $duration = 0;
151
152
    /**
153
     * Date time of the suite in ISO 8601 format (2017-07-01T12:30:01+02:00).
154
     *
155
     * @var DateTime
156
     *
157
     * @ORM\Column(name="datetime_suite", type="datetime")
158
     *
159
     * @Assert\NotBlank()
160
     * @Assert\DateTime()
161
     *
162
     * @Serializer\Groups({"public", "private"})
163
     */
164
    protected $datetime;
165
166
    /**
167
     * @Gedmo\SortablePosition
168
     * @ORM\Column(name="position", type="integer")
169
     *
170
     * @Serializer\Exclude
171
     */
172
    private $position;
173
174
    /**
175
     * @var Campaign
176
     *
177
     * @Gedmo\SortableGroup
178
     * @ORM\ManyToOne(targetEntity="Campaign")
179
     * @ORM\JoinColumn(name="campaign_id", referencedColumnName="id", nullable=false, onDelete="cascade")
180
     *
181
     * @Serializer\Exclude
182
     */
183
    private $campaign;
184
185
    /**
186
     * Constructor.
187
     *
188
     * @param Campaign $campaign
189
     */
190
    public function __construct(Campaign $campaign)
191
    {
192
        $this->setCampaign($campaign);
193
    }
194
195
    /**
196
     * Get id.
197
     *
198
     * @return int
199
     */
200
    public function getId(): int
201
    {
202
        return $this->id;
203
    }
204
205
    /**
206
     * Set name.
207
     *
208
     * @param string $name Name
209
     *
210
     * @return Suite
211
     */
212
    public function setName(string $name): Suite
213
    {
214
        $this->name = $name;
215
216
        return $this;
217
    }
218
219
    /**
220
     * Get name.
221
     *
222
     * @return string
223
     */
224
    public function getName(): string
225
    {
226
        return $this->name;
227
    }
228
229
    /**
230
     * Set passed tests count.
231
     *
232
     * @param int $passed Passed tests
233
     *
234
     * @return Suite
235
     */
236
    public function setpassed(int $passed): Suite
237
    {
238
        $this->passed = $passed;
239
240
        return $this;
241
    }
242
243
    /**
244
     * Get passed tests count.
245
     *
246
     * @return int
247
     */
248
    public function getPassed(): int
249
    {
250
        return $this->passed;
251
    }
252
253
    /**
254
     * Set failed tests count.
255
     *
256
     * @param int $failed Failed tests
257
     *
258
     * @return Suite
259
     */
260
    public function setFailed(int $failed): Suite
261
    {
262
        $this->failed = $failed;
263
264
        return $this;
265
    }
266
267
    /**
268
     * Get failed tests count.
269
     *
270
     * @return int
271
     */
272
    public function getFailed(): int
273
    {
274
        return $this->failed;
275
    }
276
277
    /**
278
     * Set errored tests count.
279
     *
280
     * @param int $errored Errored tests
281
     *
282
     * @return Suite
283
     */
284
    public function setErrored(int $errored): Suite
285
    {
286
        $this->errored = $errored;
287
288
        return $this;
289
    }
290
291
    /**
292
     * Get errored tests count.
293
     *
294
     * @return int
295
     */
296
    public function getErrored(): int
297
    {
298
        return $this->errored;
299
    }
300
301
    /**
302
     * Set skipped tests count.
303
     *
304
     * @param int $skipped Skipped tests
305
     *
306
     * @return Suite
307
     */
308
    public function setSkipped(int $skipped): Suite
309
    {
310
        $this->skipped = $skipped;
311
312
        return $this;
313
    }
314
315
    /**
316
     * Get skipped tests count.
317
     *
318
     * @return int
319
     */
320
    public function getSkipped(): int
321
    {
322
        return $this->skipped;
323
    }
324
325
    /**
326
     * Set disabled tests count.
327
     *
328
     * @param int $disabled Disable tests
329
     *
330
     * @return Suite
331
     */
332
    public function setDisabled(int $disabled): Suite
333
    {
334
        $this->disabled = $disabled;
335
336
        return $this;
337
    }
338
339
    /**
340
     * Get disabled tests count.
341
     *
342
     * @return int
343
     */
344
    public function getDisabled(): int
345
    {
346
        return $this->disabled;
347
    }
348
349
    /**
350
     * Set duration of the suite in second.
351
     *
352
     * @param float $duration Duration
353
     *
354
     * @return Suite
355
     */
356
    public function setDuration(float $duration): Suite
357
    {
358
        $this->duration = $duration;
359
360
        return $this;
361
    }
362
363
    /**
364
     * Get duration of the suite in seconds.
365
     *
366
     * @return float
367
     */
368
    public function getDuration(): float
369
    {
370
        return $this->duration;
371
    }
372
373
    /**
374
     * Set datetime of suite.
375
     *
376
     * @param DateTime $datetime DateTime of suite.
377
     *
378
     * @return Suite
379
     */
380
    public function setDateTime(DateTime $datetime): Suite
381
    {
382
        $this->datetime = $datetime;
383
384
        return $this;
385
    }
386
387
    /**
388
     * Get datetime of suite.
389
     *
390
     * @return DateTime
391
     */
392
    public function getDateTime(): DateTime
393
    {
394
        return $this->datetime;
395
    }
396
397
    /**
398
     * Set order.
399
     *
400
     * @param int $position The order.
401
     *
402
     * @return Suite
403
     */
404
    public function setPosition(int $position): Suite
405
    {
406
        $this->position = $position;
407
408
        return $this;
409
    }
410
411
    /**
412
     * Get position.
413
     *
414
     * @return int
415
     */
416
    public function getPosition(): int
417
    {
418
        return $this->position;
419
    }
420
421
    /**
422
     * Get reference id (Incremental integer).
423
     *
424
     * @return int
425
     *
426
     * @Serializer\VirtualProperty
427
     * @Serializer\SerializedName("refid")
428
     * @Serializer\Type("int")
429
     * @Serializer\Groups({"public", "private"})
430
     */
431
    public function getRefid(): int
432
    {
433
        return $this->position + 1;
434
    }
435
436
    /**
437
     * Set campaign.
438
     *
439
     * @param Campaign $campaign Campaign
440
     *
441
     * @return Suite
442
     */
443
    public function setCampaign(Campaign $campaign): Suite
444
    {
445
        $this->campaign = $campaign;
446
447
        return $this;
448
    }
449
450
    /**
451
     * Get campaign.
452
     *
453
     * @return Campaign
454
     */
455
    public function getCampaign(): Campaign
456
    {
457
        return $this->campaign;
458
    }
459
460
    /**
461
     * Get enabled tests.
462
     *
463
     * @return int
464
     */
465
    public function getEnabled(): int
466
    {
467
        return $this->passed
468
            + $this->failed
469
            + $this->errored
470
            + $this->skipped;
471
    }
472
473
    /**
474
     * Get percentage of successful tests.
475
     *
476
     * @return float
477
     */
478
    public function getPercentage(): float
479
    {
480
        if ($this->getEnabled() > 0) {
481
            return round($this->passed / $this->getEnabled() * 100);
482
        }
483
484
        return 0;
485
    }
486
487
    /**
488
     * Get suite status.
489
     *
490
     * @return int Status::FAILED|Status::WARNING|Status::SUCCESS
491
     */
492
    public function getStatus(): int
493
    {
494
        if ($this->getPercentage() < $this->campaign->getWarning()) {
495
            return Status::FAILED;
496
        }
497
        if ($this->getPercentage() < $this->campaign->getSuccess()) {
498
            return Status::WARNING;
499
        }
500
501
        return Status::SUCCESS;
502
    }
503
}
504