Skip to content

Commit c62002d

Browse files
committed
Improved TestHelper efficiency
1 parent 9a759de commit c62002d

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

lib/Phpfastcache/Helper/TestHelper.php

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class TestHelper
3636

3737
/**
3838
* TestHelper constructor.
39-
* @param $testName
39+
* @param string $testName
4040
*/
41-
public function __construct($testName)
41+
public function __construct(string $testName)
4242
{
4343
$this->timestamp = microtime(true);
4444
$this->printText('[PhpFastCache CORE v' . Api::getPhpFastCacheVersion() . Api::getPhpFastCacheGitHeadHash() . ']', true);
@@ -77,9 +77,9 @@ public function resetExitCode(): self
7777
* @param string $string
7878
* @return $this
7979
*/
80-
public function printSkipText($string): self
80+
public function printSkipText(string $string): self
8181
{
82-
$this->printText("[SKIP] {$string}");
82+
$this->printText($string, false, 'SKIP');
8383

8484
return $this;
8585
}
@@ -88,9 +88,10 @@ public function printSkipText($string): self
8888
* @param string $string
8989
* @return $this
9090
*/
91-
public function printPassText($string): self
91+
public function printPassText(string $string): self
9292
{
93-
$this->printText("[PASS] {$string}");
93+
$this->printText($string, false, 'PASS');
94+
9495

9596
return $this;
9697
}
@@ -99,9 +100,10 @@ public function printPassText($string): self
99100
* @param string printFailText
100101
* @return $this
101102
*/
102-
public function printInfoText($string): self
103+
public function printInfoText(string $string): self
103104
{
104-
$this->printText("[INFO] {$string}");
105+
$this->printText($string, false, 'INFO');
106+
105107

106108
return $this;
107109
}
@@ -110,9 +112,9 @@ public function printInfoText($string): self
110112
* @param string $string
111113
* @return $this
112114
*/
113-
public function printDebugText($string): self
115+
public function printDebugText(string $string): self
114116
{
115-
$this->printText("[DEBUG] {$string}");
117+
$this->printText($string, false, 'DEBUG');
116118

117119
return $this;
118120
}
@@ -121,9 +123,9 @@ public function printDebugText($string): self
121123
* @param string $string
122124
* @return $this
123125
*/
124-
public function printNoteText($string): self
126+
public function printNoteText(string $string): self
125127
{
126-
$this->printText("[NOTE] {$string}");
128+
$this->printText($string, false, 'NOTE');
127129

128130
return $this;
129131
}
@@ -132,9 +134,9 @@ public function printNoteText($string): self
132134
* @param string $string
133135
* @return $this
134136
*/
135-
public function printFailText($string): self
137+
public function printFailText(string $string): self
136138
{
137-
$this->printText("[FAIL] {$string}");
139+
$this->printText($string, false, 'FAIL');
138140
$this->exitCode = 1;
139141

140142
return $this;
@@ -144,22 +146,23 @@ public function printFailText($string): self
144146
* @param int $count
145147
* @return $this
146148
*/
147-
public function printNewLine($count = 1): self
149+
public function printNewLine(int $count = 1): self
148150
{
149-
for ($i = 0; $i < $count; $i++) {
150-
print PHP_EOL;
151-
}
152-
151+
print \str_repeat(PHP_EOL, $count);
153152
return $this;
154153
}
155154

156155
/**
157-
* @param $string
156+
* @param string $string
158157
* @param bool $strtoupper
158+
* @param string $prefix
159159
* @return $this
160160
*/
161-
public function printText($string, $strtoupper = false): self
161+
public function printText(string $string, bool $strtoupper = false, string $prefix = ''): self
162162
{
163+
if($prefix){
164+
$string = "[{$prefix}] {$string}";
165+
}
163166
if (!$strtoupper) {
164167
print \trim($string) . PHP_EOL;
165168
} else {
@@ -172,7 +175,7 @@ public function printText($string, $strtoupper = false): self
172175
/**
173176
* @param string $cmd
174177
*/
175-
public function runAsyncProcess($cmd)
178+
public function runAsyncProcess(string $cmd)
176179
{
177180
if (\substr(\php_uname(), 0, 7) === 'Windows') {
178181
\pclose(\popen('start /B ' . $cmd, 'r'));
@@ -185,7 +188,7 @@ public function runAsyncProcess($cmd)
185188
* @param string $file
186189
* @param string $ext
187190
*/
188-
public function runSubProcess($file, $ext = '.php')
191+
public function runSubProcess(string $file, string $ext = '.php')
189192
{
190193
$this->runAsyncProcess(($this->isHHVM() ? 'hhvm ' : 'php ') . \getcwd() . \DIRECTORY_SEPARATOR . 'subprocess' . \DIRECTORY_SEPARATOR . $file . '.subprocess' . $ext);
191194
}

0 commit comments

Comments
 (0)