diff options
Diffstat (limited to 'vendor/j4mie/idiorm/test/CacheTest.php')
-rw-r--r-- | vendor/j4mie/idiorm/test/CacheTest.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/j4mie/idiorm/test/CacheTest.php b/vendor/j4mie/idiorm/test/CacheTest.php new file mode 100644 index 000000000..a3daa91d0 --- /dev/null +++ b/vendor/j4mie/idiorm/test/CacheTest.php @@ -0,0 +1,42 @@ +<?php + +class CacheTest 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); + ORM::configure('caching', true); + ORM::configure('caching', true, self::ALTERNATE); + } + + public function tearDown() { + ORM::reset_config(); + ORM::reset_db(); + } + + // Test caching. This is a bit of a hack. + public function testQueryGenerationOnlyOccursOnce() { + ORM::for_table('widget')->where('name', 'Fred')->where('age', 17)->find_one(); + ORM::for_table('widget')->where('name', 'Bob')->where('age', 42)->find_one(); + $expected = ORM::get_last_query(); + ORM::for_table('widget')->where('name', 'Fred')->where('age', 17)->find_one(); // this shouldn't run a query! + $this->assertEquals($expected, ORM::get_last_query()); + } + + public function testQueryGenerationOnlyOccursOnceWithMultipleConnections() { + // Test caching with multiple connections (also a bit of a hack) + ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one(); + ORM::for_table('widget', self::ALTERNATE)->where('name', 'Tom')->where('age', 120)->find_one(); + $expected = ORM::get_last_query(); + ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one(); // this shouldn't run a query! + $this->assertEquals($expected, ORM::get_last_query(self::ALTERNATE)); + } + +}
\ No newline at end of file |