1
|
|
|
<?php |
2
|
|
|
//require 'PHPUnit/Autoload.php'; |
3
|
|
|
|
4
|
|
|
require __DIR__ . '/bootstrap.php'; |
5
|
|
|
|
6
|
|
|
if (!defined('PHPUnit_MAIN_METHOD')) { |
7
|
|
|
define('PHPUnit_MAIN_METHOD', 'KochTest\AllTests::main'); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
class AllTests |
11
|
|
|
{ |
12
|
|
|
public static function main() |
13
|
|
|
{ |
14
|
|
|
PHPUnit_TextUI_TestRunner::run(self::suite()); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public static function suite() |
18
|
|
|
{ |
19
|
|
|
$suite = new PHPUnit_Framework_TestSuite('Koch Framework - TestSuite'); |
20
|
|
|
foreach (self::getTestFiles() as $file) { |
21
|
|
|
$suite->addFile$file); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
return $suite; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tries to find in CLI parameters and returns array of files to be runj by PHPUnit |
29
|
|
|
* or throws Exception if no such parameter found or directory/file does not exist. |
30
|
|
|
* |
31
|
|
|
* @return array an array of files to be run by PHPUnit |
32
|
|
|
*/ |
33
|
|
|
private static function getTestFiles() |
34
|
|
|
{ |
35
|
|
|
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); |
36
|
|
|
$run = null; |
37
|
|
|
foreach ($argv as $arg) { |
38
|
|
|
if (preg_match("/^\"?" . self::RUN . "(.+?)\"?$/", $arg, $sub)) { |
39
|
|
|
$run = $sub[1]; |
40
|
|
|
break; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
if ($run === null) { |
44
|
|
|
throw new Exception("No argument to run found."); |
45
|
|
|
} |
46
|
|
|
if (is_dir($run)) { |
47
|
|
|
return self::rglob("*[Tt]est.php", $run . DIRECTORY_SEPARATOR); |
48
|
|
|
} elseif (is_file($run)) { |
49
|
|
|
return array($run); |
50
|
|
|
} |
51
|
|
|
throw new Exception(sprintf("Argument '%s' neither file nor directory.", $run)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Recursive glob(). |
56
|
|
|
* |
57
|
|
|
* @param string $pattern the pattern passed to glob(), default is "*" |
58
|
|
|
* @param string $path the path to scan, default is |
59
|
|
|
* @param int $flags the flags passed to glob() |
60
|
|
|
* @return array an array of files in the given path matching the pattern. |
61
|
|
|
*/ |
62
|
|
|
private static function rglob($pattern = '*', $path = '', $flags = 0) |
63
|
|
|
{ |
64
|
|
|
$paths = glob($path . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT) or array(); |
65
|
|
|
$files = glob($path . $pattern, $flags) or array(); |
66
|
|
|
foreach ($paths as $path) { |
67
|
|
|
$files += self::rglob($pattern, $path, $flags); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $files; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (PHPUnit_MAIN_METHOD == 'AllTests::main') { |
75
|
|
|
AllTests::main(); |
76
|
|
|
} |
77
|
|
|
|