Completed
Push — V6 ( 3e1d9a...98ae5f )
by Georges
02:13
created

TestHelper::getExitCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace phpFastCache\Helper;
3
4
use phpFastCache\Api;
5
6
/**
7
 * Class TestHelper
8
 * @package phpFastCache\Helper
9
 */
10
class TestHelper
11
{
12
    /**
13
     * @var int
14
     */
15
    protected $exitCode = 0;
16
17
    public function __construct($testName)
18
    {
19
        $this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true);
20
        $this->printText("[Begin Test: '{$testName}']");
21
        $this->printText('---');
22
    }
23
24
    /**
25
     * @return int
26
     */
27
    public function getExitCode()
28
    {
29
        return $this->exitCode;
30
    }
31
32
    /**
33
     * @return $this
34
     */
35
    public function resetExitCode()
36
    {
37
        $this->exitCode = 0;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param string $string
44
     * @return $this
45
     */
46
    public function printSkipText($string)
47
    {
48
        $this->printText("[SKIP] {$string}");
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param string $string
55
     * @return $this
56
     */
57
    public function printPassText($string)
58
    {
59
        $this->printText("[PASS] {$string}");
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param string $string
66
     * @return $this
67
     */
68
    public function printFailText($string)
69
    {
70
        $this->printText("[FAIL] {$string}");
71
        $this->exitCode = 1;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @param int $count
78
     * @return $this
79
     */
80
    public function printNewLine($count = 1)
81
    {
82
        for($i = 0; $i < $count; $i++){
83
            print PHP_EOL;
84
        }
85
86
        return $this;
87
    }
88
89
    /**
90
     * @param $string
91
     * @param bool $strtoupper
92
     * @return $this
93
     */
94
    public function printText($string, $strtoupper = false)
95
    {
96
        if(!$strtoupper){
97
            print trim($string) . PHP_EOL;
98
        }else{
99
            print strtoupper(trim($string) . PHP_EOL);
100
        }
101
102
        return $this;
103
    }
104
105
    /**
106
     * @return void
107
     */
108
    public function terminateTest()
109
    {
110
        exit($this->exitCode);
0 ignored issues
show
Coding Style Compatibility introduced by
The method terminateTest() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
111
    }
112
}