diff options
author | Jamie Matthews <[email protected]> | 2010-09-20 11:54:57 +0100 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2010-09-20 11:54:57 +0100 |
commit | 46ec3309310972b5199a13bc48926bb933a6b939 (patch) | |
tree | c29dbf4be99895d1f67aab1b3e63a0accdb9f42b /test | |
parent | f37277495a6cfec9d28dc09af19f791664a93000 (diff) |
Test framework now works better when invoked from the command line
Diffstat (limited to 'test')
-rw-r--r-- | test/test_classes.php | 25 | ||||
-rw-r--r-- | test/test_queries.php | 4 |
2 files changed, 21 insertions, 8 deletions
diff --git a/test/test_classes.php b/test/test_classes.php index e0bacfe..2bfcb2a 100644 --- a/test/test_classes.php +++ b/test/test_classes.php @@ -105,10 +105,23 @@ } /** + * Format a line for printing. Detects + * if the script is being run from the command + * line or from a browser. + */ + private static function format_line($line) { + if (isset($_SERVER['HTTP_USER_AGENT'])) { + return "<p>$line</p>\n"; + } else { + return "$line\n"; + } + } + + /** * Report a passed test */ private static function report_pass($test_name) { - echo "<p>PASS: $test_name</p>"; + echo self::format_line("PASS: $test_name"); self::$passed_tests[] = $test_name; } @@ -116,9 +129,9 @@ * Report a failed test */ private static function report_failure($test_name, $query) { - echo "<p>FAIL: $test_name</p>"; - echo "<p>Expected: $query</p>"; - echo "<p>Actual: " . self::$db->get_last_query() . "</p>"; + echo self::format_line("FAIL: $test_name"); + echo self::format_line("Expected: $query"); + echo self::format_line("Actual: " . self::$db->get_last_query()); self::$failed_tests[] = $test_name; } @@ -128,10 +141,10 @@ public static function report() { $passed_count = count(self::$passed_tests); $failed_count = count(self::$failed_tests); - echo "<p>$passed_count tests passed. $failed_count tests failed.</p>"; + echo self::format_line("$passed_count tests passed. $failed_count tests failed."); if ($failed_count != 0) { - echo "<p>Failed tests: " . join(", ", self::$failed_tests) . "</p>"; + echo self::format_line("Failed tests: " . join(", ", self::$failed_tests)); } } diff --git a/test/test_queries.php b/test/test_queries.php index 88c3ba8..8a281ee 100644 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -6,8 +6,8 @@ * */ - require_once "../idiorm.php"; - require_once "test_classes.php"; + require_once dirname(__FILE__) . "/../idiorm.php"; + require_once dirname(__FILE__) . "/test_classes.php"; // Set up the dummy database connection $db = new DummyPDO(); |