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 | |
parent | 4973256bb5a2d280619025aabe4f0c045bbe6e38 (diff) |
Improved comments for test classes, moved all testing functionality out of main ORM class.
-rw-r--r-- | idiorm.php | 18 | ||||
-rw-r--r-- | test/test_classes.php | 38 | ||||
-rw-r--r-- | test/test_queries.php | 9 |
3 files changed, 39 insertions, 26 deletions
@@ -405,24 +405,6 @@ } /** - * For debugging only. Returns a string representation of the query - * that would be executed by calling run() on the current instance of the - * class. 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 build as expected. - */ - public function as_sql() { - $sql = $this->build_select(); - $sql = str_replace("?", "%s", $sql); - - $quoted_values = array(); - foreach ($this->values as $value) { - $quoted_values[] = '"' . $value . '"'; - } - return vsprintf($sql, $quoted_values); - } - - /** * Return the value of a property of this object (database row) * or null if not present. */ 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()) { 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 @@ <?php - // Basic testing for Idiorm + /* + * Basic testing for Idiorm + * + * Checks that the generated SQL is correct + * + */ require_once "../idiorm.php"; require_once "test_classes.php"; @@ -68,7 +73,5 @@ $expected = 'DELETE FROM widget WHERE id = "1"'; Tester::check_equal("Delete data", $expected); - - Tester::report(); ?> |