summaryrefslogtreecommitdiff
path: root/vendor/j4mie/idiorm/test/MulitpleConnectionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/j4mie/idiorm/test/MulitpleConnectionTest.php')
-rw-r--r--vendor/j4mie/idiorm/test/MulitpleConnectionTest.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/j4mie/idiorm/test/MulitpleConnectionTest.php b/vendor/j4mie/idiorm/test/MulitpleConnectionTest.php
new file mode 100644
index 000000000..a58f3ca83
--- /dev/null
+++ b/vendor/j4mie/idiorm/test/MulitpleConnectionTest.php
@@ -0,0 +1,52 @@
+<?php
+
+class MultipleConnectionTest extends PHPUnit_Framework_TestCase {
+
+ const ALTERNATE = 'alternate'; // Used as name of alternate connection
+
+ public function setUp() {
+ // Set up the dummy database connections
+ ORM::set_db(new MockPDO('sqlite::memory:'));
+ ORM::set_db(new MockDifferentPDO('sqlite::memory:'), self::ALTERNATE);
+
+ // Enable logging
+ ORM::configure('logging', true);
+ ORM::configure('logging', true, self::ALTERNATE);
+ }
+
+ public function tearDown() {
+ ORM::reset_config();
+ ORM::reset_db();
+ }
+
+ public function testMultiplePdoConnections() {
+ $this->assertInstanceOf('MockPDO', ORM::get_db());
+ $this->assertInstanceOf('MockPDO', ORM::get_db(ORM::DEFAULT_CONNECTION));
+ $this->assertInstanceOf('MockDifferentPDO', ORM::get_db(self::ALTERNATE));
+ }
+
+ public function testRawExecuteOverAlternateConnection() {
+ $expected = "SELECT * FROM `foo`";
+ ORM::raw_execute("SELECT * FROM `foo`", array(), self::ALTERNATE);
+
+ $this->assertEquals($expected, ORM::get_last_query(self::ALTERNATE));
+ }
+
+ public function testFindOneOverDifferentConnections() {
+ ORM::for_table('widget')->find_one();
+ $statementOne = ORM::get_last_statement();
+ $this->assertInstanceOf('MockPDOStatement', $statementOne);
+
+ ORM::for_table('person', self::ALTERNATE)->find_one();
+ $statementOne = ORM::get_last_statement(); // get_statement is *not* per connection
+ $this->assertInstanceOf('MockDifferentPDOStatement', $statementOne);
+
+ $expected = "SELECT * FROM `widget` LIMIT 1";
+ $this->assertNotEquals($expected, ORM::get_last_query()); // Because get_last_query() is across *all* connections
+ $this->assertEquals($expected, ORM::get_last_query(ORM::DEFAULT_CONNECTION));
+
+ $expectedToo = "SELECT * FROM `person` LIMIT 1";
+ $this->assertEquals($expectedToo, ORM::get_last_query(self::ALTERNATE));
+ }
+
+} \ No newline at end of file