From 46ec3309310972b5199a13bc48926bb933a6b939 Mon Sep 17 00:00:00 2001 From: Jamie Matthews Date: Mon, 20 Sep 2010 11:54:57 +0100 Subject: Test framework now works better when invoked from the command line --- test/test_classes.php | 25 +++++++++++++++++++------ test/test_queries.php | 4 ++-- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'test') 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 @@ -104,11 +104,24 @@ self::$db = $db; } + /** + * 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 "

$line

\n"; + } else { + return "$line\n"; + } + } + /** * Report a passed test */ private static function report_pass($test_name) { - echo "

PASS: $test_name

"; + 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 "

FAIL: $test_name

"; - echo "

Expected: $query

"; - echo "

Actual: " . self::$db->get_last_query() . "

"; + 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 "

$passed_count tests passed. $failed_count tests failed.

"; + echo self::format_line("$passed_count tests passed. $failed_count tests failed."); if ($failed_count != 0) { - echo "

Failed tests: " . join(", ", self::$failed_tests) . "

"; + 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(); -- cgit v1.2.3