-
-
Notifications
You must be signed in to change notification settings - Fork 456
/
Copy pathRunTests.php
89 lines (76 loc) · 2.93 KB
/
RunTests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <[email protected]>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
define('PFC_TEST_DIR', \realpath(__DIR__));
$timestamp = microtime(true);
$climate = new League\CLImate\CLImate;
$climate->forceAnsiOn();
$phpBinPath = 'php ';
$status = 0;
$dir = __DIR__;
$projectDir = dirname($dir, 2);
$driver = $argv[ 1 ] ?? 'Files';
$phpBinPath = $_SERVER['PHP_BIN_PATH'] ?? 'php';
$failedTests = [];
$skippedTests = [];
/**
* @param string $pattern
* @param int $flags
* @return array
*/
$globCallback = static function (string $pattern, int $flags = 0) use (&$globCallback): array {
$files = \glob($pattern, $flags);
$subFiles = [];
foreach (\glob(\dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$subFiles[] = $globCallback($dir . '/' . \basename($pattern), $flags);
}
return \array_merge(...$subFiles, ...[$files]);
};
foreach ($globCallback(PFC_TEST_DIR . DIRECTORY_SEPARATOR . '*.test.php') as $filename) {
$climate->backgroundLightYellow()->blue()->out('---');
$command = "{$phpBinPath} -f {$filename} {$driver}";
$shortCommand = str_replace(dirname(PFC_TEST_DIR), '~', $command);
$climate->out("<yellow>phpfastcache@unit-tests</yellow> <blue>{$projectDir}</blue> <green>#</green> <red>$shortCommand</red>");
\exec($command, $output, $return_var);
$climate->out('=====================================');
$climate->out(\implode("\n", $output));
$climate->out('=====================================');
if ($return_var === 0) {
$climate->green("Test finished successfully");
} elseif ($return_var === 2) {
$climate->yellow("Test skipped due to unmeet dependencies");
$skippedTests[] = basename($filename);
} else {
$climate->red("Test finished with a least one error");
$status = 1;
$failedTests[] = basename($filename);
}
$climate->out('');
/**
* Reset $output to prevent override effects
*/
unset($output);
}
$execTime = gmdate('i\m s\s', (int) round(microtime(true) - $timestamp, 3));
$climate->out('<yellow>Total tests duration: </yellow><light_green>' . $execTime . '</light_green>');
if (!$failedTests) {
$climate->backgroundGreen()->white()->flank('[OK] The build has passed successfully', '#')->out('');
} else {
$climate->backgroundRed()->white()->flank('[KO] The build has failed miserably', '~')->out('');
$climate->red()->out('[TESTS FAILED] ' . PHP_EOL . '- '. implode(PHP_EOL . '- ', $failedTests))->out('');
}
if ($skippedTests) {
$climate->yellow()->out('[TESTS SKIPPED] ' . PHP_EOL . '- '. implode(PHP_EOL . '- ', $skippedTests))->out('');
}
exit($status);