Merge "Make it possible to sort on simple custom columns"
[ninja.git] / modules / test / libraries / Ninja_Unit_Test.php
blob3b4d7857884e10a52a36f912fee826835504fddc
1 <?php
3 require_once unittest::tap_path();
5 /**
6 * Wrapper around the tapunit wrapper around phptap
7 */
8 class Ninja_Unit_Test {
9 function __construct() {
10 $paths = array('test/unit_test');
11 ob_end_clean();
12 $main_tap = new phptap("Ninja unit test suite");
14 $argv = isset($argv) ? $argv : $GLOBALS['argv'];
15 $argc = isset($argc) ? $argc : $GLOBALS['argc'];
16 $files = array();
17 for ($i = 1; $i < $argc; $i++) {
18 switch ($argv[$i]) {
19 case '--file':
20 $files[] = $argv[$i + 1];
21 break;
25 foreach ($paths as $path) {
26 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME)) as $path => $file) {
27 // Skip files without "_Test" suffix
28 if ( ! $file->isFile() OR substr($path, -9) !== '_Test'.EXT)
29 continue;
31 // The class name should be the same as the file name
32 $class = substr($path, strrpos($path, '/') + 1, -(strlen(EXT)));
34 // Skip hidden files
35 if (substr($class, 0, 1) === '.')
36 continue;
38 // skip unless defined specific one on cli
39 if(count($files) > 0 and !in_array($class, $files))
40 continue;
42 // Check for duplicate test class name
43 if (class_exists($class, FALSE))
44 $main_tap->fail("Duplicate test class: $class in $path");
46 // Include the test class
47 include_once $path;
48 runUnit($class, $main_tap);
52 $exit_code = $main_tap->done(false);
53 exit((int)($exit_code > 1));