diff options
author | Simon Holywell <[email protected]> | 2018-01-03 17:14:25 +1000 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2018-01-03 17:14:25 +1000 |
commit | 5f220f371dc250b1c65dfb5f767ebc8b8b40a92d (patch) | |
tree | c586545a9ce6e85522e96f4936b98d6986333193 | |
parent | 16a53cddf06739c910d7899684370442daa01a4c (diff) |
Closes #319 - no reset on cached response
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | idiorm.php | 12 | ||||
-rw-r--r-- | test/CacheIntegrationTest.php | 36 |
3 files changed, 46 insertions, 3 deletions
@@ -4,3 +4,4 @@ docs/_build /phpunit.phar /vendor /composer.lock +.DS_Store @@ -1899,6 +1899,7 @@ $cached_result = self::_check_query_cache($cache_key, $this->_table_name, $this->_connection_name); if ($cached_result !== false) { + $this->_reset_idiorm_state(); return $cached_result; } } @@ -1915,12 +1916,17 @@ self::_cache_query_result($cache_key, $rows, $this->_table_name, $this->_connection_name); } - // reset Idiorm after executing the query + $this->_reset_idiorm_state(); + return $rows; + } + + /** + * Reset the Idiorm instance state + */ + private function _reset_idiorm_state() { $this->_values = array(); $this->_result_columns = array('*'); $this->_using_default_result_columns = true; - - return $rows; } /** diff --git a/test/CacheIntegrationTest.php b/test/CacheIntegrationTest.php new file mode 100644 index 0000000..ae56880 --- /dev/null +++ b/test/CacheIntegrationTest.php @@ -0,0 +1,36 @@ +<?php + +class CacheIntegrationTest extends PHPUnit_Framework_TestCase { + + public function setUp() { + ORM::configure('sqlite::memory:'); + ORM::configure('logging', true); + ORM::configure('caching', true); + + ORM::raw_execute('CREATE TABLE `league` ( `class_id` INTEGER )'); + ORM::raw_execute('INSERT INTO `league`(`class_id`) VALUES (1), (2), (3)'); + } + + public function tearDown() { + ORM::raw_execute('DROP TABLE `league`'); + } + + public function testRegressionForPullRequest319() { + $rs = ORM::for_table('league')->where('class_id', 1); + $total = $rs->count(); + $this->assertEquals(1, $total); + $row = $rs->find_one(); + $this->assertEquals(array('class_id' => 1), $row->as_array()); + + $rs = ORM::for_table('league')->where('class_id', 1); + $total = $rs->count(); + $this->assertEquals(1, $total); + try { + $row = $rs->find_one(); + } catch(PDOException $e) { + $this->fail("Caching is breaking subsequent queries!\n{$e->getMessage()}"); + } + $this->assertEquals(array('class_id' => 1), $row->as_array()); + } + +} |