diff options
author | Jamie Matthews <[email protected]> | 2010-02-13 11:29:02 +0000 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2010-02-13 11:29:02 +0000 |
commit | 17dcdb192ad826be20c4a8ae313f5a7a0bc313d4 (patch) | |
tree | f94a8ad5398bb73ad162d11f430f44adacd0d3fc /test/test_classes.php | |
parent | 4973256bb5a2d280619025aabe4f0c045bbe6e38 (diff) |
Improved comments for test classes, moved all testing functionality out of main ORM class.
Diffstat (limited to 'test/test_classes.php')
-rw-r--r-- | test/test_classes.php | 38 |
1 files changed, 33 insertions, 5 deletions
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 "<p>PASS: $test_name</p>"; self::$passed_tests[] = $test_name; } + /** + * Report a failed test + */ private static function report_failure($test_name, $query) { echo "<p>FAIL: $test_name</p>"; echo "<p>Expected: $query</p>"; @@ -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()) { |