summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2013-01-18 13:20:00 +0000
committerSimon Holywell <[email protected]>2013-01-18 13:20:00 +0000
commitdee4dd8166d47c69fe982b701cee40c44f9aabea (patch)
tree4eb8c598f05af3553ec1a1d603fb241c4dabacbe /test
parentf9a6f92e3e38a4235438c14d5e1c205f331133ee (diff)
Move out non-query gen tests
Diffstat (limited to 'test')
-rw-r--r--test/CacheTest.php29
-rw-r--r--test/ORMTest.php6
2 files changed, 35 insertions, 0 deletions
diff --git a/test/CacheTest.php b/test/CacheTest.php
new file mode 100644
index 0000000..ef079aa
--- /dev/null
+++ b/test/CacheTest.php
@@ -0,0 +1,29 @@
+<?php
+
+class CacheTest extends PHPUnit_Framework_TestCase {
+
+ public function setUp() {
+ // Enable logging
+ ORM::configure('logging', true);
+ ORM::configure('caching', true);
+
+ // Set up the dummy database connection
+ $db = new MockPDO('sqlite::memory:');
+ ORM::set_db($db);
+ }
+
+ public function tearDown() {
+ ORM::configure('logging', false);
+ ORM::configure('caching', false);
+ ORM::set_db(null);
+ }
+
+ // 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());
+ }
+} \ No newline at end of file
diff --git a/test/ORMTest.php b/test/ORMTest.php
index 81a5b05..ced3cbd 100644
--- a/test/ORMTest.php
+++ b/test/ORMTest.php
@@ -78,4 +78,10 @@ class ORMTest extends PHPUnit_Framework_TestCase {
$this->assertSame(count($result_set), 5);
}
+ public function testGetLastPdoStatement() {
+ ORM::for_table('widget')->where('name', 'Fred')->find_one();
+ $statement = ORM::get_last_statement();
+ $this->assertInstanceOf('MockPDOStatement', $statement);
+ }
+
} \ No newline at end of file