From 17dcdb192ad826be20c4a8ae313f5a7a0bc313d4 Mon Sep 17 00:00:00 2001 From: Jamie Matthews Date: Sat, 13 Feb 2010 11:29:02 +0000 Subject: Improved comments for test classes, moved all testing functionality out of main ORM class. --- test/test_classes.php | 38 +++++++++++++++++++++++++++++++++----- test/test_queries.php | 9 ++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/test_classes.php b/test/test_classes.php index 15f3c77..e0bacfe 100644 --- a/test/test_classes.php +++ b/test/test_classes.php @@ -2,12 +2,15 @@ /** * - * Mock database classes implementing a subset - * of the PDO API. Used for testing Idiorm. + * Mock version of the PDOStatement class. Can be + * used to get a string representing a "bound" version + * of the query. Because PDO works using prepared statements, + * this can provide only a rough representation of the + * query, but this will usually be enough to check that + * your query has been built as expected. * */ - - class DummyStatement { + class DummyPDOStatement { private $query = ''; private $input_parameters = array(); @@ -52,6 +55,12 @@ } + /** + * + * Mock database class implementing a subset + * of the PDO API. + * + */ class DummyPDO { private $last_query; @@ -63,7 +72,7 @@ } public function prepare($statement) { - $this->last_query = new DummyStatement($statement); + $this->last_query = new DummyPDOStatement($statement); return $this->last_query; } @@ -77,7 +86,9 @@ } /** + * * Class to provide simple testing functionality + * */ class Tester { @@ -85,15 +96,25 @@ private static $failed_tests = array(); private static $db; + /** + * Set the dummy database connection to be + * used by the class to capture the SQL strings + */ public static function set_db($db) { self::$db = $db; } + /** + * Report a passed test + */ private static function report_pass($test_name) { echo "

PASS: $test_name

"; self::$passed_tests[] = $test_name; } + /** + * Report a failed test + */ private static function report_failure($test_name, $query) { echo "

FAIL: $test_name

"; echo "

Expected: $query

"; @@ -101,6 +122,9 @@ self::$failed_tests[] = $test_name; } + /** + * Print a summary of passed and failed test counts + */ public static function report() { $passed_count = count(self::$passed_tests); $failed_count = count(self::$failed_tests); @@ -111,6 +135,10 @@ } } + /** + * Check the provided string is equal to the last + * query generated by the dummy database class. + */ public static function check_equal($test_name, $query) { $last_query = self::$db->get_last_query(); if ($query == self::$db->get_last_query()) { diff --git a/test/test_queries.php b/test/test_queries.php index de85023..109e778 100644 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -1,5 +1,10 @@ -- cgit v1.2.3