Skip to content

Commit f08608c

Browse files
committed
Updated Lexer Test
1 parent c3ae192 commit f08608c

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lib/Phpfastcache/Helper/TestHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ class TestHelper
2929
*/
3030
protected $exitCode = 0;
3131

32+
/**
33+
* @var int
34+
*/
35+
protected $timestamp;
36+
3237
/**
3338
* TestHelper constructor.
3439
* @param $testName
3540
*/
3641
public function __construct($testName)
3742
{
43+
$this->timestamp = microtime(true);
3844
$this->printText('[PhpFastCache CORE v' . Api::getPhpFastCacheVersion() . Api::getPhpFastCacheGitHeadHash() . ']', true);
3945
$this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true);
4046
$this->printText('[PHP v' . PHP_VERSION . ']', true);
@@ -178,6 +184,9 @@ public function runSubProcess($file, $ext = '.php')
178184
*/
179185
public function terminateTest()
180186
{
187+
$execTime = round(microtime(true) - $this->timestamp, 3);
188+
189+
$this->printText('Test finished in ' . $execTime . 's');
181190
exit($this->exitCode);
182191
}
183192

tests/lexer/LexerCheck.test.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?php
22

3+
use Phpfastcache\Helper\TestHelper;
4+
35
chdir(__DIR__ . '/../../');
6+
require_once __DIR__ . '/../../vendor/autoload.php';
7+
$testHelper = new TestHelper('PHP Lexer');
8+
49

510
/**
611
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
712
* @author Georges.L (Geolim4) <[email protected]>
813
*/
914

10-
function read_dir($dir, $ext = null)
15+
function phpfastcache_read_dir($dir, $ext = null)
1116
{
1217
$list = [];
1318
$dir .= '/';
@@ -20,7 +25,7 @@ function read_dir($dir, $ext = null)
2025
}
2126
$name = $dir . $name;
2227
if (is_dir($name)) {
23-
$list = array_merge($list, read_dir($name, $ext));
28+
$list = array_merge($list, phpfastcache_read_dir($name, $ext));
2429
} elseif (is_file($name)) {
2530
if (!is_null($ext) && substr(strrchr($name, '.'), 1) != $ext) {
2631
continue;
@@ -32,29 +37,18 @@ function read_dir($dir, $ext = null)
3237
return $list;
3338
}
3439

35-
$list = read_dir('./lib', 'php');
40+
$list = phpfastcache_read_dir('./lib', 'php');
3641

37-
$exit = 0;
38-
foreach ($list as $file) {
42+
foreach (array_map('realpath', $list) as $file) {
3943
$output = '';
40-
/**
41-
* @todo Make the exclusions much cleaner
42-
*/
43-
if (strpos($file, '/vendor/composer') === false && strpos($file, '/bin/stubs') === false) {
44-
exec((defined('HHVM_VERSION') ? 'hhvm' : 'php') . ' -l "' . realpath($file) . '"', $output, $status);
45-
} else {
46-
echo '[SKIP] ' . $file;
47-
echo "\n";
48-
continue;
49-
}
44+
\exec(($testHelper->isHHVM() ? 'hhvm' : 'php') . ' -l "' . $file . '"', $output, $status);
45+
46+
$output = trim(implode("\n", $output));
5047

5148
if ($status !== 0) {
52-
$exit = $status;
53-
echo '[FAIL]';
49+
$testHelper->printFailText($output ?: "Syntax error found in {$file}");
5450
} else {
55-
echo '[PASS]';
51+
$testHelper->printPassText($output ?: "No syntax errors detected in {$file}");
5652
}
57-
echo ' ' . implode("\n", $output);
58-
echo "\n";
5953
}
60-
exit($exit);
54+
$testHelper->terminateTest();

0 commit comments

Comments
 (0)