Completed
Push — master ( 2b33dd...92e09f )
by FX
03:29
created

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