1 | <?php |
||
23 | class TestHelper |
||
24 | { |
||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $exitCode = 0; |
||
29 | |||
30 | /** |
||
31 | * TestHelper constructor. |
||
32 | * @param $testName |
||
33 | */ |
||
34 | public function __construct($testName) |
||
35 | { |
||
36 | $this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true); |
||
37 | $this->printText("[Begin Test: '{$testName}']"); |
||
38 | $this->printText('---'); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return int |
||
43 | */ |
||
44 | public function getExitCode() |
||
45 | { |
||
46 | return $this->exitCode; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function resetExitCode() |
||
53 | { |
||
54 | $this->exitCode = 0; |
||
55 | |||
56 | return $this; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param string $string |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function printSkipText($string) |
||
64 | { |
||
65 | $this->printText("[SKIP] {$string}"); |
||
66 | |||
67 | return $this; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param string $string |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function printPassText($string) |
||
75 | { |
||
76 | $this->printText("[PASS] {$string}"); |
||
77 | |||
78 | return $this; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param string $string |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function printFailText($string) |
||
86 | { |
||
87 | $this->printText("[FAIL] {$string}"); |
||
88 | $this->exitCode = 1; |
||
89 | |||
90 | return $this; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param int $count |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function printNewLine($count = 1) |
||
98 | { |
||
99 | for ($i = 0; $i < $count; $i++) { |
||
100 | print PHP_EOL; |
||
101 | } |
||
102 | |||
103 | return $this; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param $string |
||
108 | * @param bool $strtoupper |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function printText($string, $strtoupper = false) |
||
112 | { |
||
113 | if (!$strtoupper) { |
||
114 | print trim($string) . PHP_EOL; |
||
115 | } else { |
||
116 | print strtoupper(trim($string) . PHP_EOL); |
||
117 | } |
||
118 | |||
119 | return $this; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param string $cmd |
||
124 | */ |
||
125 | public function runAsyncProcess($cmd) |
||
126 | { |
||
127 | if (substr(php_uname(), 0, 7) === 'Windows') { |
||
128 | pclose(popen('start /B ' . $cmd, 'r')); |
||
129 | } else { |
||
130 | exec($cmd . ' > /dev/null &'); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @param string $file |
||
136 | * @param string $ext |
||
137 | */ |
||
138 | public function runSubProcess($file, $ext = '.php') |
||
142 | |||
143 | /** |
||
144 | * @return void |
||
145 | */ |
||
146 | public function terminateTest() |
||
150 | |||
151 | /** |
||
152 | * @param $obj |
||
153 | * @param $prop |
||
154 | * @return mixed |
||
155 | * @throws \ReflectionException |
||
156 | */ |
||
157 | public function accessInaccessibleMember($obj, $prop) { |
||
158 | $reflection = new \ReflectionClass($obj); |
||
159 | $property = $reflection->getProperty($prop); |
||
163 | |||
164 | } |
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.