Skip to content

Commit

Permalink
Closes #319 - no reset on cached response
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Jan 3, 2018
1 parent 16a53cd commit 5f220f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs/_build
/phpunit.phar
/vendor
/composer.lock
.DS_Store
12 changes: 9 additions & 3 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,7 @@ protected function _run() {
$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;
}
}
Expand All @@ -1915,12 +1916,17 @@ protected function _run() {
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;
}

/**
Expand Down
36 changes: 36 additions & 0 deletions test/CacheIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit 5f220f3

Please sign in to comment.