Completed
Push — master ( 14bf01...b7c3ef )
by FX
04:41
created

Test::getSystemerr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
    /**
52
     * @var int
53
     *
54
     * @ORM\Column(name="id", type="integer")
55
     * @ORM\Id
56
     * @ORM\GeneratedValue(strategy="AUTO")
57
     *
58
     * @Serializer\Exclude
59
     */
60
    private $id;
61
62
    /**
63
     * @var string
64
     *
65
     * @ORM\Column(name="name", type="string", length=256)
66
     *
67
     * @Assert\NotBlank
68
     *
69
     * @Serializer\Groups({"public", "private"})
70
     */
71
    private $name;
72
73
    /**
74
     * @var string
75
     *
76
     * @ORM\Column(name="classname", type="string", length=256)
77
     *
78
     * @Serializer\Groups({"public", "private"})
79
     */
80
    private $classname;
81
82
    /**
83
     * @var string
84
     *
85
     * @ORM\Column(name="package", type="string", length=256)
86
     *
87
     * @Serializer\Groups({"public", "private"})
88
     */
89
    private $package;
90
91
    /**
92
     * @var int
93
     *
94
     * @ORM\Column(name="passed", type="smallint")
95
     *
96
     * @Assert\Type("integer")
97
     * @Assert\GreaterThanOrEqual(0)
98
     *
99
     * @Serializer\Exclude
100
     */
101
    private $passed;
102
103
    /**
104
     * @var int
105
     *
106
     * @ORM\Column(name="failed", type="smallint")
107
     *
108
     * @Assert\Type("integer")
109
     * @Assert\GreaterThanOrEqual(0)
110
     *
111
     * @Serializer\Exclude
112
     */
113
    private $failed;
114
115
    /**
116
     * @var int
117
     *
118
     * @ORM\Column(name="errored", type="smallint")
119
     *
120
     * @Assert\Type("integer")
121
     * @Assert\GreaterThanOrEqual(0)
122
     *
123
     * @Serializer\Exclude
124
     */
125
    private $errored;
126
127
    /**
128
     * @var int
129
     *
130
     * @ORM\Column(name="skipped", type="smallint")
131
     *
132
     * @Assert\Type("integer")
133
     * @Assert\GreaterThanOrEqual(0)
134
     *
135
     * @Serializer\Exclude
136
     */
137
    private $skipped;
138
139
    /**
140
     * @var float
141
     *
142
     * @ORM\Column(name="duration", type="float")
143
     *
144
     * @Assert\Type("float")
145
     * @Assert\GreaterThanOrEqual(0)
146
     *
147
     * @Serializer\Groups({"public", "private"})
148
     */
149
    private $duration;
150
151
    /**
152
     * @var string
153
     *
154
     * @ORM\Column(name="system_out", type="text")
155
     *
156
     * @Serializer\Groups({"public", "private"})
157
     */
158
    private $systemout;
159
160
    /**
161
     * @var string
162
     *
163
     * @ORM\Column(name="system_err", type="text")
164
     *
165
     * @Serializer\Groups({"public", "private"})
166
     */
167
    private $systemerr;
168
169
    /**
170
     * @Gedmo\SortablePosition
171
     *
172
     * @ORM\Column(name="position", type="integer"))
173
     */
174
    private $position;
175
176
    /**
177
     * @var Suite
178
     *
179
     * @Gedmo\SortableGroup
180
     *
181
     * @ORM\ManyToOne(targetEntity="Suite")
182
     * @ORM\JoinColumn(name="suite_id", referencedColumnName="id", nullable=false, onDelete="cascade")
183
     *
184
     * @Serializer\Exclude
185
     */
186
    private $suite;
187
188
    /**
189
     * Constructor.
190
     *
191
     * @param Suite $suite The suite
192
     */
193
    public function __construct(Suite $suite)
194
    {
195
        $this->setSuite($suite);
196
    }
197
198
    /**
199
     * Get id.
200
     *
201
     * @return int
202
     */
203
    public function getId(): int
204
    {
205
        return $this->id;
206
    }
207
208
    /**
209
     * Set name.
210
     *
211
     * @param string $name Name
212
     *
213
     * @return Test
214
     */
215
    public function setName(string $name): Test
216
    {
217
        $this->name = $name;
218
219
        return $this;
220
    }
221
222
    /**
223
     * Get name.
224
     *
225
     * @return string
226
     */
227
    public function getName(): string
228
    {
229
        return $this->name;
230
    }
231
232
    /**
233
     * Set class name.
234
     *
235
     * @param string $classname Class name
236
     *
237
     * @return Test
238
     */
239
    public function setClassname(string $classname): Test
240
    {
241
        $this->classname = $classname;
242
243
        return $this;
244
    }
245
246
    /**
247
     * Get class name.
248
     *
249
     * @return string
250
     */
251
    public function getClassname(): string
252
    {
253
        return $this->classname;
254
    }
255
256
    /**
257
     * Set package.
258
     *
259
     * @param string $package Package of the test
260
     *
261
     * @return Test
262
     */
263
    public function setPackage(string $package): Test
264
    {
265
        $this->package = $package;
266
267
        return $this;
268
    }
269
270
    /**
271
     * Get package.
272
     *
273
     * @return string
274
     */
275
    public function getPackage(): string
276
    {
277
        return $this->package;
278
    }
279
280
    /**
281
     * Set full class name including package.
282
     *
283
     * @param string $fullClassname The full class name
284
     *
285
     * @return Test
286
     */
287 View Code Duplication
    public function setFullclassname(string $fullClassname): Test
288
    {
289
        if (substr_count($fullClassname, '.') > 0) {
290
            $index = strrpos($fullClassname, '.');
291
            $this->setPackage(substr($fullClassname, 0, $index));
292
            $this->setClassname(substr($fullClassname, $index + 1));
293
        } else {
294
            $this->setPackage(self::DEFAULT_PACKAGE);
295
            $this->setClassname($fullClassname);
296
        }
297
298
        return $this;
299
    }
300
301
    /**
302
     * Set test to passed.
303
     *
304
     * @return Test
305
     */
306 View Code Duplication
    public function setPassed(): Test
307
    {
308
        $this->passed = 1;
309
        $this->failed = 0;
310
        $this->errored = 0;
311
        $this->skipped = 0;
312
313
        return $this;
314
    }
315
316
    /**
317
     * Return 1 if test is passed.
318
     *
319
     * @return int
320
     */
321
    public function getPassed(): int
322
    {
323
        return $this->passed;
324
    }
325
326
    /**
327
     * Set test to failed.
328
     *
329
     * @return Test
330
     */
331 View Code Duplication
    public function setFailed(): Test
332
    {
333
        $this->passed = 0;
334
        $this->failed = 1;
335
        $this->errored = 0;
336
        $this->skipped = 0;
337
338
        return $this;
339
    }
340
341
    /**
342
     * Return 1 if test is failed.
343
     *
344
     * @return int
345
     */
346
    public function getFailed(): int
347
    {
348
        return $this->failed;
349
    }
350
351
    /**
352
     * Set test to errored.
353
     *
354
     * @return Test
355
     */
356 View Code Duplication
    public function setErrored(): Test
357
    {
358
        $this->passed = 0;
359
        $this->failed = 0;
360
        $this->errored = 1;
361
        $this->skipped = 0;
362
363
        return $this;
364
    }
365
366
    /**
367
     * Return 1 if test is errored.
368
     *
369
     * @return int
370
     */
371
    public function getErrored(): int
372
    {
373
        return $this->errored;
374
    }
375
376
    /**
377
     * Set test to skipped.
378
     *
379
     * @return Test
380
     */
381 View Code Duplication
    public function setSkipped(): Test
382
    {
383
        $this->passed = 0;
384
        $this->failed = 0;
385
        $this->errored = 0;
386
        $this->skipped = 1;
387
388
        return $this;
389
    }
390
391
    /**
392
     * Return 1 if test is skipped.
393
     *
394
     * @return int
395
     */
396
    public function getSkipped(): int
397
    {
398
        return $this->skipped;
399
    }
400
401
    /**
402
     * Set status of test.
403
     *
404
     * @param int $status Status (const of Status class)
405
     *
406
     * @return Test
407
     */
408
    public function setStatus(int $status): Test
409
    {
410
        switch ($status) {
411
            case Status::SUCCESS:
412
                $this->setPassed();
413
                break;
414
            case Status::FAILED:
415
                $this->setFailed();
416
                break;
417
            case Status::ERROR:
418
                $this->setErrored();
419
                break;
420
            case Status::SKIPPED:
421
                $this->setSkipped();
422
                break;
423
        }
424
425
        return $this;
426
    }
427
428
    /**
429
     * Return  status (const of Status class).
430
     *
431
     * @return int
432
     */
433
    public function getStatus(): int
434
    {
435
        if ($this->passed > 0) {
436
            return Status::SUCCESS;
437
        }
438
        if ($this->failed > 0) {
439
            return Status::FAILED;
440
        }
441
        if ($this->skipped > 0) {
442
            return Status::SKIPPED;
443
        }
444
445
        return Status::ERROR;
446
    }
447
448
    /**
449
     * Get label of status.
450
     *
451
     * @return string
452
     */
453
    public function getLabelstatus(): string
454
    {
455
        return Status::getLabel($this->getStatus());
456
    }
457
458
    /**
459
     * Set duration in seconds.
460
     *
461
     * @param float $duration Duration
462
     *
463
     * @return Test
464
     */
465
    public function setDuration(float $duration): Test
466
    {
467
        $this->duration = $duration;
468
469
        return $this;
470
    }
471
472
    /**
473
     * Get duration in seconds.
474
     *
475
     * @return float
476
     */
477
    public function getDuration(): float
478
    {
479
        return $this->duration;
480
    }
481
482
    /**
483
     * Set system out message.
484
     *
485
     * @param string $systemOut The message
486
     *
487
     * @return Test
488
     */
489
    public function setSystemout(string $systemOut): Test
490
    {
491
        $this->systemout = $systemOut;
492
493
        return $this;
494
    }
495
496
    /**
497
     * Get system out message.
498
     *
499
     * @return string
500
     */
501
    public function getSystemout(): string
502
    {
503
        return $this->systemout;
504
    }
505
506
    /**
507
     * Set system error message.
508
     *
509
     * @param string $systemErr The message
510
     *
511
     * @return Test
512
     */
513
    public function setSystemerr(string $systemErr): Test
514
    {
515
        $this->systemerr = $systemErr;
516
517
        return $this;
518
    }
519
520
    /**
521
     * Get system error message.
522
     *
523
     * @return string
524
     */
525
    public function getSystemerr(): string
526
    {
527
        return $this->systemerr;
528
    }
529
530
    /**
531
     * Set order.
532
     *
533
     * @param int $position The order.
534
     *
535
     * @return Test
536
     */
537
    public function setPosition(int $position): Test
538
    {
539
        $this->position = $position;
540
541
        return $this;
542
    }
543
544
    /**
545
     * Get position.
546
     *
547
     * @return int
548
     */
549
    public function getPosition(): int
550
    {
551
        return $this->position;
552
    }
553
554
    /**
555
     * Get reference id.
556
     *
557
     * @return int
558
     *
559
     * @Serializer\VirtualProperty
560
     * @Serializer\SerializedName("refid")
561
     * @Serializer\Type("int")
562
     * @Serializer\Groups({"public", "private"})
563
     */
564
    public function getRefid(): int
565
    {
566
        return $this->position + 1;
567
    }
568
569
    /**
570
     * Set suite.
571
     *
572
     * @param Suite $suite
573
     *
574
     * @return Test
575
     */
576
    public function setSuite(Suite $suite): Test
577
    {
578
        $this->suite = $suite;
579
580
        return $this;
581
    }
582
583
    /**
584
     * Get suite.
585
     *
586
     * @return Suite
587
     */
588
    public function getSuite(): Suite
589
    {
590
        return $this->suite;
591
    }
592
593
    /**
594
     * Set from DTO test.
595
     *
596
     * @param TestDTO $dto DTO object
597
     *
598
     * @return Test
599
     */
600
    public function setFromDTO(TestDTO $dto): Test
601
    {
602
        $this->setName($dto->getName());
603
        $this->setClassname($dto->getClassname());
604
        $this->setPackage($dto->getPackage());
605
        $this->setStatus($dto->getStatus());
606
        $this->setDuration($dto->getDuration());
607
        $this->setSystemout($dto->getSystemout());
608
        $this->setSystemerr($dto->getSystemerr());
609
610
        return $this;
611
    }
612
}
613