summaryrefslogtreecommitdiff
path: root/test/test_classes.php
diff options
context:
space:
mode:
authortag <[email protected]>2012-11-23 22:51:33 -0500
committertag <[email protected]>2012-11-23 22:51:33 -0500
commit7c95314624d427e99a5213e2868d305f421b6962 (patch)
treede4ba72e89a9177582f3a824260f094ee9f87a6f /test/test_classes.php
parent13d291f4442d268ba170b6635e44cd11d3f1049b (diff)
Multiple connection support for Idiorm
Mutiple connections code, including documentation and unit tests. Utilizes key names to distinguish connections, but uses a default connection if none specified. I don't (yet) use multiple connections in my work (it's pending), so this has not been tested "in the wild". Added unit tests with additional connections, ran unit tests for Paris against this build too, so an unmodified Paris is forward-compatible with this commit (mulitple connections support not yet coded for Paris). Does *NOT* add support for queries across multiple connections. (I don't even want to go there ...) ##### Edge-case compatibility breaks: * ORM::_setup_identifier_quote_character visibility was changed to protected (which was likely original intent, judging by prefixed name) * May break compatibility if ORM has been extended, **and** subclasses directly utilize `::_config`, `::_db`, `::_query_log`, or `::_query_cache` instead of using pre-existing accessor methods. (Paris does not do this; all Paris tests pass) * Re-use of `Tester` class outside of Idiorm repo, as `Tester::check_equal()` was renamed to `Tester::check_equal_query()` ##### Other notes New method: `ORM::get_connection_keys()`. New `Tester` method: `Tester::check_equal_string()`. TODO: Consider adding methods to get (connection-specific) configuration info.
Diffstat (limited to 'test/test_classes.php')
-rw-r--r--test/test_classes.php57
1 files changed, 53 insertions, 4 deletions
diff --git a/test/test_classes.php b/test/test_classes.php
index a948d01..cf805c0 100644
--- a/test/test_classes.php
+++ b/test/test_classes.php
@@ -11,7 +11,11 @@
/**
* Return some dummy data
*/
- public function fetch($fetch_style=PDO::FETCH_BOTH, $cursor_orientation=PDO::FETCH_ORI_NEXT, $cursor_offset=0) {
+ public function fetch(
+ $fetch_style = PDO::FETCH_BOTH,
+ $cursor_orientation = PDO::FETCH_ORI_NEXT,
+ $cursor_offset = 0
+ ) {
if ($this->current_row == 5) {
return false;
} else {
@@ -39,6 +43,44 @@
}
/**
+ * Another mock PDOStatement class, for testing multiple connections
+ */
+ class DummyDifferentPDOStatement extends PDOStatement {
+
+ private $current_row = 0;
+ /**
+ * Return some dummy data
+ */
+ public function fetch(
+ $fetch_style = PDO::FETCH_BOTH,
+ $cursor_orientation = PDO::FETCH_ORI_NEXT,
+ $cursor_offset = 0
+ ) {
+ if ($this->current_row == 5) {
+ return false;
+ } else {
+ $this->current_row++;
+ return array('name' => 'Steve', 'age' => 80, 'id' => "{$this->current_row}");
+ }
+ }
+ }
+
+ /**
+ * A different mock database class, for testing multiple connections
+ * Mock database class implementing a subset of the PDO API.
+ */
+ class DummyDifferentPDO extends PDO {
+
+ /**
+ * Return a dummy PDO statement
+ */
+ public function prepare($statement, $driver_options = array()) {
+ $this->last_query = new DummyDifferentPDOStatement($statement);
+ return $this->last_query;
+ }
+ }
+
+ /**
*
* Class to provide simple testing functionality
*
@@ -110,12 +152,19 @@
* Check the provided string is equal to the last
* query generated by the dummy database class.
*/
- public static function check_equal($test_name, $query) {
+ public static function check_equal_query($test_name, $query) {
$last_query = ORM::get_last_query();
- if ($query === $last_query) {
+ self::check_equal_string($test_name, $query, $last_query);
+ }
+
+ /**
+ * Check the provided strings are equal
+ */
+ public static function check_equal_string($test_name, $s1, $s2) {
+ if ($s1 === $s2) {
self::report_pass($test_name);
} else {
- self::report_failure($test_name, $query, $last_query);
+ self::report_failure($test_name, $s1, $s2);
}
}
}