diff options
-rw-r--r-- | test/test_classes.php | 10 | ||||
-rwxr-xr-x | test/test_queries.php | 18 |
2 files changed, 20 insertions, 8 deletions
diff --git a/test/test_classes.php b/test/test_classes.php index a948d01..ff31764 100644 --- a/test/test_classes.php +++ b/test/test_classes.php @@ -5,7 +5,7 @@ * Mock version of the PDOStatement class. * */ - class DummyPDOStatement extends PDOStatement { + class MockPDOStatement extends PDOStatement { private $current_row = 0; /** @@ -27,13 +27,13 @@ * of the PDO API. * */ - class DummyPDO extends PDO { + class MockPDO extends PDO { /** * Return a dummy PDO statement */ public function prepare($statement, $driver_options=array()) { - $this->last_query = new DummyPDOStatement($statement); + $this->last_query = new MockPDOStatement($statement); return $this->last_query; } } @@ -77,7 +77,7 @@ /** * Report a passed test */ - private static function report_pass($test_name) { + public static function report_pass($test_name) { echo self::format_line("PASS: $test_name", 'GREEN'); self::$passed_tests[] = $test_name; } @@ -85,7 +85,7 @@ /** * Report a failed test */ - private static function report_failure($test_name, $expected, $actual) { + public static function report_failure($test_name, $expected, $actual) { echo self::format_line("FAIL: $test_name", 'RED'); echo self::format_line("Expected: $expected", 'RED'); echo self::format_line("Actual: $actual", 'RED'); diff --git a/test/test_queries.php b/test/test_queries.php index 8cc26d6..d3749cb 100755 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -13,7 +13,7 @@ ORM::configure('logging', true); // Set up the dummy database connection - $db = new DummyPDO('sqlite::memory:'); + $db = new MockPDO('sqlite::memory:'); ORM::set_db($db); ORM::for_table('widget')->find_many(); @@ -299,6 +299,19 @@ $expected = "INSERT OR IGNORE INTO `widget` (`id`, `name`) VALUES ('1', 'Tolstoy')"; Tester::check_equal("Raw execute", $expected); // A bit of a silly test, as query is passed through + ORM::for_table('widget')->where('name', 'Fred')->find_one(); + $statement = ORM::get_last_statement(); + $test_name = 'get_last_statement() returned MockPDOStatement'; + if($statement instanceOf MockPDOStatement) { + Tester::report_pass($test_name); + } else { + $actual = gettype($statement); + if('object' == $actual) { + $actual = get_class($statement); + } + Tester::report_failure($test_name, 'MockPDOStatement', $actual); + } + // Regression tests $widget = ORM::for_table('widget')->select('widget.*')->find_one(); @@ -358,5 +371,4 @@ Tester::check_equal("Caching, same query not run twice", $expected); - Tester::report(); -?> + Tester::report();
\ No newline at end of file |