Permalink
Browse files

Fixing various faling tests. The problem was not closing the statemen…

…ts, among other things
  • Loading branch information...
lorenzo committed Feb 12, 2014
1 parent 645fd49 commit 70e3ef04cf6e8cba4c585ecb69d53294807dfbbc
@@ -88,7 +88,8 @@ protected function _stringifyValues($generator) {
$type = $this->_type;
$multiType = is_array($type);
$isMulti = $this->isMulti($i, $type);
$type = $isMulti ? str_replace('[]', '', $type) : $type;
$type = $multiType ? $type : str_replace('[]', '', $type);
$type = $type ?: null;
if ($isMulti) {
$bound = [];
@@ -313,6 +313,7 @@ protected function _linkField($options) {
*/
protected function _buildSubquery($query, $foreignKey) {
$filterQuery = clone $query;
$filterQuery->limit(null);
$filterQuery->contain([], true);
$joins = $filterQuery->join();
foreach ($joins as $i => $join) {
@@ -780,8 +780,7 @@ public function first() {
if ($this->_dirty) {
$this->limit(1);
}
$this->_results = $this->all();
return $this->_results->first();
return $this->all()->first();
}
/**
@@ -113,6 +113,13 @@ class ResultSet implements Countable, Iterator, Serializable, JsonSerializable {
*/
protected $_useBuffering = true;
/**
* Holds the count of records in this result set
*
* @var integer
*/
protected $_count;
/**
* Constructor
*
@@ -128,6 +135,10 @@ public function __construct($query, $statement) {
$this->_hydrate = $this->_query->hydrate();
$this->_entityClass = $query->repository()->entityClass();
$this->_useBuffering = $query->bufferResults();
if ($statement) {
$this->count();
}
}
/**
@@ -199,8 +210,9 @@ public function valid() {
$this->_current = $this->_fetchResult();
$valid = $this->_current !== false;
$hasNext = $this->_index < $this->_count;
if (!$valid && $this->_statement) {
if ($this->_statement && !($valid && $hasNext)) {
$this->_statement->closeCursor();
}
@@ -271,10 +283,13 @@ public function first() {
* @return integer
*/
public function count() {
if ($this->_count !== null) {
return $this->_count;
}
if ($this->_statement) {
return $this->_statement->rowCount();
return $this->_count = $this->_statement->rowCount();
}
return count($this->_results);
return $this->_count = count($this->_results);

This comment has been minimized.

@markstory

markstory Feb 13, 2014

Member

I'm guessing these are workarounds for PDO being sad?

This comment has been minimized.

@lorenzo

lorenzo Feb 13, 2014

Member

This was part of the changes for fixing TranslateBehavior, and yes, it is just to please PDO :P

This comment has been minimized.

@markstory

markstory Feb 13, 2014

Member

Oh PDO u so crazy.

}
/**
@@ -426,6 +426,7 @@ public function testFindSingleLocaleBelongsto() {
$results = $table->find()
->select(['title', 'body'])
->order(['title' => 'asc'])
->contain(['Authors' => function($q) {
return $q->select(['id', 'name']);
}]);
@@ -885,7 +885,10 @@ public function testResultsAreWrappedInMapReduce() {
$params = [$this->connection, $this->table];
$query = $this->getMock('\Cake\ORM\Query', ['execute'], $params);
$statement = $this->getMock('\Database\StatementInterface', ['fetch', 'closeCursor']);
$statement = $this->getMock(
'\Database\StatementInterface',
['fetch', 'closeCursor', 'rowCount']
);
$statement->expects($this->exactly(3))
->method('fetch')
->will($this->onConsecutiveCalls(['a' => 1], ['a' => 2], false));

0 comments on commit 70e3ef0

Please sign in to comment.