Passed
Push — master ( c8dc71...ea5fcd )
by FX
02:35
created

Test::getErrored()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Copyright (c) 2017 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of ci-report.
7
 *
8
 * ci-report is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * ci-report is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Entity;
24
25
use AppBundle\DTO\TestDTO;
26
use Doctrine\ORM\Mapping as ORM;
27
use Gedmo\Mapping\Annotation as Gedmo;
28
use JMS\Serializer\Annotation as Serializer;
29
use Symfony\Component\Validator\Constraints as Assert;
30
31
/**
32
 * Test entity class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://www.ci-report.io
41
 *
42
 * @ORM\Table(name="cir_test")
43
 * @ORM\Entity(repositoryClass="AppBundle\Repository\TestRepository")
44
 */
45
class Test
46
{
47
    const DEFAULT_NAME = 'DEFAULT_NAME';
48
    const DEFAULT_CLASSNAME = 'DEFAULT_CLASSNAME';
49
    const DEFAULT_PACKAGE = '_ROOT_';
50
51
    const PASSED = 'Passed';
52
    const FAILED = 'Failed';
53
    const ERRORED = 'Errored';
54
    const SKIPPED = 'Skipped';
55
56
    /**
57
     * @var int
58
     *
59
     * @ORM\Column(name="id", type="integer")
60
     * @ORM\Id
61
     * @ORM\GeneratedValue(strategy="AUTO")
62
     *
63
     * @Serializer\Exclude
64
     */
65
    private $id;
66
67
    /**
68
     * @var string
69
     *
70
     * @ORM\Column(name="name", type="string", length=256)
71
     *
72
     * @Assert\NotBlank
73
     *
74
     * @Serializer\Groups({"public", "private"})
75
     */
76
    private $name;
77
78
    /**
79
     * @var string
80
     *
81
     * @ORM\Column(name="classname", type="string", length=256)
82
     *
83
     * @Serializer\Groups({"public", "private"})
84
     */
85
    private $classname;
86
87
    /**
88
     * @var string
89
     *
90
     * @ORM\Column(name="package", type="string", length=256)
91
     *
92
     * @Serializer\Groups({"public", "private"})
93
     */
94
    private $package;
95
96
    /**
97
     * @var int
98
     *
99
     * @ORM\Column(name="passed", type="smallint")
100
     *
101
     * @Assert\Type("integer")
102
     * @Assert\GreaterThanOrEqual(0)
103
     *
104
     * @Serializer\Exclude
105
     */
106
    private $passed;
107
108
    /**
109
     * @var int
110
     *
111
     * @ORM\Column(name="failed", type="smallint")
112
     *
113
     * @Assert\Type("integer")
114
     * @Assert\GreaterThanOrEqual(0)
115
     *
116
     * @Serializer\Exclude
117
     */
118
    private $failed;
119
120
    /**
121
     * @var int
122
     *
123
     * @ORM\Column(name="errored", type="smallint")
124
     *
125
     * @Assert\Type("integer")
126
     * @Assert\GreaterThanOrEqual(0)
127
     *
128
     * @Serializer\Exclude
129
     */
130
    private $errored;
131
132
    /**
133
     * @var int
134
     *
135
     * @ORM\Column(name="skipped", type="smallint")
136
     *
137
     * @Assert\Type("integer")
138
     * @Assert\GreaterThanOrEqual(0)
139
     *
140
     * @Serializer\Exclude
141
     */
142
    private $skipped;
143
144
    /**
145
     * @var float
146
     *
147
     * @ORM\Column(name="duration", type="float")
148
     *
149
     * @Assert\Type("float")
150
     * @Assert\GreaterThanOrEqual(0)
151
     *
152
     * @Serializer\Groups({"public", "private"})
153
     */
154
    private $duration;
155
156
    /**
157
     * @var string
158
     *
159
     * @ORM\Column(name="system_out", type="text")
160
     *
161
     * @Serializer\Groups({"public", "private"})
162
     */
163
    private $systemout = '';
164
165
    /**
166
     * @var string
167
     *
168
     * @ORM\Column(name="system_err", type="text")
169
     *
170
     * @Serializer\Groups({"public", "private"})
171
     */
172
    private $systemerr = '';
173
174
    /**
175
     * @var string
176
     *
177
     * @ORM\Column(name="failure_msg", type="text")
178
     *
179
     * @Serializer\Groups({"public", "private"})
180
     */
181
    private $failuremsg = '';
182
183
    /**
184
     * @Gedmo\SortablePosition
185
     *
186
     * @ORM\Column(name="position", type="integer"))
187
     */
188
    private $position;
189
190
    /**
191
     * @var Suite
192
     *
193
     * @Gedmo\SortableGroup
194
     *
195
     * @ORM\ManyToOne(targetEntity="Suite")
196
     * @ORM\JoinColumn(name="suite_id", referencedColumnName="id", nullable=false, onDelete="cascade")
197
     *
198
     * @Serializer\Exclude
199
     */
200
    private $suite;
201
202
    /**
203
     * Constructor.
204
     *
205
     * @param Suite $suite The suite
206
     */
207
    public function __construct(Suite $suite)
208
    {
209
        $this->setSuite($suite);
210
    }
211
212
    /**
213
     * Get id.
214
     *
215
     * @return int
216
     */
217
    public function getId(): int
218
    {
219
        return $this->id;
220
    }
221
222
    /**
223
     * Set name.
224
     *
225
     * @param string $name Name
226
     *
227
     * @return Test
228
     */
229
    public function setName(string $name): self
230
    {
231
        $this->name = $name;
232
233
        return $this;
234
    }
235
236
    /**
237
     * Get name.
238
     *
239
     * @return string
240
     */
241
    public function getName(): string
242
    {
243
        return $this->name;
244
    }
245
246
    /**
247
     * Set class name.
248
     *
249
     * @param string $classname Class name
250
     *
251
     * @return Test
252
     */
253
    public function setClassname(string $classname): self
254
    {
255
        $this->classname = $classname;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Get class name.
262
     *
263
     * @return string
264
     */
265
    public function getClassname(): string
266
    {
267
        return $this->classname;
268
    }
269
270
    /**
271
     * Set package.
272
     *
273
     * @param string $package Package of the test
274
     *
275
     * @return Test
276
     */
277
    public function setPackage(string $package): self
278
    {
279
        $this->package = $package;
280
281
        return $this;
282
    }
283
284
    /**
285
     * Get package.
286
     *
287
     * @return string
288
     */
289
    public function getPackage(): string
290
    {
291
        return $this->package;
292
    }
293
294
    /**
295
     * Set full class name including package.
296
     *
297
     * @param string $fullClassname The full class name
298
     *
299
     * @return Test
300
     */
301 View Code Duplication
    public function setFullclassname(string $fullClassname): self
302
    {
303
        if (substr_count($fullClassname, '.') > 0) {
304
            $index = strrpos($fullClassname, '.');
305
            $this->setPackage(substr($fullClassname, 0, $index));
306
            $this->setClassname(substr($fullClassname, $index + 1));
307
        } else {
308
            $this->setPackage(self::DEFAULT_PACKAGE);
309
            $this->setClassname($fullClassname);
310
        }
311
312
        return $this;
313
    }
314
315
    /**
316
     * Set test to passed.
317
     *
318
     * @return Test
319
     */
320
    public function setPassed(): self
321
    {
322
        $this->passed = 1;
323
        $this->failed = 0;
324
        $this->errored = 0;
325
        $this->skipped = 0;
326
327
        return $this;
328
    }
329
330
    /**
331
     * Return 1 if test is passed.
332
     *
333
     * @return int
334
     */
335
    public function getPassed(): int
336
    {
337
        return $this->passed;
338
    }
339
340
    /**
341
     * Set test to failed.
342
     *
343
     * @return Test
344
     */
345
    public function setFailed(): self
346
    {
347
        $this->passed = 0;
348
        $this->failed = 1;
349
        $this->errored = 0;
350
        $this->skipped = 0;
351
352
        return $this;
353
    }
354
355
    /**
356
     * Return 1 if test is failed.
357
     *
358
     * @return int
359
     */
360
    public function getFailed(): int
361
    {
362
        return $this->failed;
363
    }
364
365
    /**
366
     * Set test to errored.
367
     *
368
     * @return Test
369
     */
370
    public function setErrored(): self
371
    {
372
        $this->passed = 0;
373
        $this->failed = 0;
374
        $this->errored = 1;
375
        $this->skipped = 0;
376
377
        return $this;
378
    }
379
380
    /**
381
     * Return 1 if test is errored.
382
     *
383
     * @return int
384
     */
385
    public function getErrored(): int
386
    {
387
        return $this->errored;
388
    }
389
390
    /**
391
     * Set test to skipped.
392
     *
393
     * @return Test
394
     */
395
    public function setSkipped(): self
396
    {
397
        $this->passed = 0;
398
        $this->failed = 0;
399
        $this->errored = 0;
400
        $this->skipped = 1;
401
402
        return $this;
403
    }
404
405
    /**
406
     * Return 1 if test is skipped.
407
     *
408
     * @return int
409
     */
410
    public function getSkipped(): int
411
    {
412
        return $this->skipped;
413
    }
414
415
    /**
416
     * Set status of test.
417
     *
418
     * @param string $status Status (const of Test class)
419
     *
420
     * @return Test
421
     */
422
    public function setStatus(string $status): self
423
    {
424
        switch ($status) {
425
            case self::PASSED:
426
                $this->setPassed();
427
                break;
428
            case self::FAILED:
429
                $this->setFailed();
430
                break;
431
            case self::ERRORED:
432
                $this->setErrored();
433
                break;
434
            case self::SKIPPED:
435
                $this->setSkipped();
436
                break;
437
        }
438
439
        return $this;
440
    }
441
442
    /**
443
     * Return  status (const of Test class).
444
     *
445
     * @return string
446
     */
447
    public function getStatus(): string
448
    {
449
        if ($this->passed > 0) {
450
            return self::PASSED;
451
        }
452
        if ($this->failed > 0) {
453
            return self::FAILED;
454
        }
455
        if ($this->skipped > 0) {
456
            return self::SKIPPED;
457
        }
458
459
        return self::ERRORED;
460
    }
461
462
    /**
463
     * Set duration in seconds.
464
     *
465
     * @param float $duration Duration
466
     *
467
     * @return Test
468
     */
469
    public function setDuration(float $duration): self
470
    {
471
        $this->duration = $duration;
472
473
        return $this;
474
    }
475
476
    /**
477
     * Get duration in seconds.
478
     *
479
     * @return float
480
     */
481
    public function getDuration(): float
482
    {
483
        return $this->duration;
484
    }
485
486
    /**
487
     * Set system out message.
488
     *
489
     * @param string $systemOut The message
490
     *
491
     * @return Test
492
     */
493
    public function setSystemout(string $systemOut): self
494
    {
495
        $this->systemout = $systemOut;
496
497
        return $this;
498
    }
499
500
    /**
501
     * Get system out message.
502
     *
503
     * @return string
504
     */
505
    public function getSystemout(): string
506
    {
507
        return $this->systemout;
508
    }
509
510
    /**
511
     * Set system error message.
512
     *
513
     * @param string $systemErr The message
514
     *
515
     * @return Test
516
     */
517
    public function setSystemerr(string $systemErr): self
518
    {
519
        $this->systemerr = $systemErr;
520
521
        return $this;
522
    }
523
524
    /**
525
     * Get system error message.
526
     *
527
     * @return string
528
     */
529
    public function getSystemerr(): string
530
    {
531
        return $this->systemerr;
532
    }
533
534
    /**
535
     * Set failure message.
536
     *
537
     * @param string $failureMsg The message
538
     *
539
     * @return Test
540
     */
541
    public function setFailuremsg(string $failureMsg): self
542
    {
543
        $this->failuremsg = $failureMsg;
544
545
        return $this;
546
    }
547
548
    /**
549
     * Get failure message.
550
     *
551
     * @return string
552
     */
553
    public function getFailuremsg(): string
554
    {
555
        return $this->failuremsg;
556
    }
557
558
    /**
559
     * Set order.
560
     *
561
     * @param int $position The order.
562
     *
563
     * @return Test
564
     */
565
    public function setPosition(int $position): self
566
    {
567
        $this->position = $position;
568
569
        return $this;
570
    }
571
572
    /**
573
     * Get position.
574
     *
575
     * @return int
576
     */
577
    public function getPosition(): int
578
    {
579
        return $this->position;
580
    }
581
582
    /**
583
     * Get reference id.
584
     *
585
     * @return int
586
     *
587
     * @Serializer\VirtualProperty
588
     * @Serializer\SerializedName("refid")
589
     * @Serializer\Type("int")
590
     * @Serializer\Groups({"public", "private"})
591
     */
592
    public function getRefid(): int
593
    {
594
        return $this->position + 1;
595
    }
596
597
    /**
598
     * Set suite.
599
     *
600
     * @param Suite $suite
601
     *
602
     * @return Test
603
     */
604
    public function setSuite(Suite $suite): self
605
    {
606
        $this->suite = $suite;
607
608
        return $this;
609
    }
610
611
    /**
612
     * Get suite.
613
     *
614
     * @return Suite
615
     */
616
    public function getSuite(): Suite
617
    {
618
        return $this->suite;
619
    }
620
621
    /**
622
     * Set from DTO test.
623
     *
624
     * @param TestDTO $dto DTO object
625
     *
626
     * @return Test
627
     */
628
    public function setFromDTO(TestDTO $dto): self
629
    {
630
        $this->setName($dto->getName());
631
        $this->setClassname($dto->getClassname());
632
        $this->setPackage($dto->getPackage());
633
        $this->setStatus($dto->getStatus());
634
        $this->setDuration($dto->getDuration());
635
        $this->setSystemout($dto->getSystemout());
636
        $this->setSystemerr($dto->getSystemerr());
637
        $this->setFailuremsg($dto->getFailuremsg());
638
639
        return $this;
640
    }
641
}
642