public function testMemcaching() { ORM::configure('caching', true); ORM::configure('caching_driver', 'memcache'); ORM::addMemcacheServer(array('host' => '127.0.0.1', 'port' => '11211')); ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne(); ORM::forTable('widget')->where('name', 'Bob')->where('age', 42)->findOne(); $expected = ORM::getLastQuery(); // this shouldn't run a query! ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne(); $this->assertEquals($expected, ORM::getLastQuery()); Orm::clearCache(); // this should run now. ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne(); $this->assertEquals("SELECT * FROM `widget` WHERE `name` = 'Fred' AND `age` = '17' LIMIT 1", Orm::getLastQuery()); }
public function testComplexRelationships() { $book = Model::factory('Book')->findOne(1); $authors = $book->authors()->findMany(); $expected = "SELECT `author`.* FROM `author` JOIN `author_book` ON `author`.`id` = `author_book`.`author_id` WHERE `author_book`.`book_id` = '1'"; $this->assertEquals($expected, ORM::getLastQuery()); $book2 = Model::factory('BookTwo')->findOne(1); $authors2 = $book2->authors()->findMany(); $expected = "SELECT `author_two`.* FROM `author_two` JOIN `wrote_the_book` ON `author_two`.`id` = `wrote_the_book`.`custom_author_id` WHERE `wrote_the_book`.`custom_book_id` = '1'"; $this->assertEquals($expected, ORM::getLastQuery()); $this->assertEquals($expected, ORM::getLastQuery()); }