summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-02-13 11:29:02 +0000
committerJamie Matthews <[email protected]>2010-02-13 11:29:02 +0000
commit17dcdb192ad826be20c4a8ae313f5a7a0bc313d4 (patch)
treef94a8ad5398bb73ad162d11f430f44adacd0d3fc /test
parent4973256bb5a2d280619025aabe4f0c045bbe6e38 (diff)
Improved comments for test classes, moved all testing functionality out of main ORM class.
Diffstat (limited to 'test')
-rw-r--r--test/test_classes.php38
-rw-r--r--test/test_queries.php9
2 files changed, 39 insertions, 8 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()) {
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();
?>