Browse Source

Refactoring to make all ORM tests pass on HHVM for SQlite

Jose Lorenzo Rodriguez 11 years ago
parent
commit
026ea94f8a
2 changed files with 14 additions and 23 deletions
  1. 12 21
      src/ORM/ResultSet.php
  2. 2 2
      tests/TestCase/ORM/QueryTest.php

+ 12 - 21
src/ORM/ResultSet.php

@@ -217,21 +217,23 @@ class ResultSet implements ResultSetInterface
      */
      */
     public function valid()
     public function valid()
     {
     {
-        if ($this->_results[$this->_index] !== null) {
+        if ($this->_index >= $this->_count) {
+            if ($this->_statement !== null) {
+                $this->_statement->closeCursor();
+            }
+            return false;
+        }
+
+        if ($this->_useBuffering && $this->_results[$this->_index] !== null) {
             $this->_current = $this->_results[$this->_index];
             $this->_current = $this->_results[$this->_index];
             return true;
             return true;
         }
         }
 
 
         $this->_current = $this->_fetchResult();
         $this->_current = $this->_fetchResult();
         $valid = $this->_current !== false;
         $valid = $this->_current !== false;
-        $hasNext = $this->_index < $this->_count;
 
 
-        if ($this->_statement && !($valid && $hasNext)) {
-            $this->_statement->closeCursor();
-        }
-
-        if ($valid) {
-            $this->_bufferResult($this->_current);
+        if ($this->_useBuffering) {
+            $this->_results[$this->_index] = $this->_current;
         }
         }
 
 
         return $valid;
         return $valid;
@@ -263,6 +265,8 @@ class ResultSet implements ResultSetInterface
     public function unserialize($serialized)
     public function unserialize($serialized)
     {
     {
         $this->_results = unserialize($serialized);
         $this->_results = unserialize($serialized);
+        $this->_useBuffering = true;
+        $this->_count = count($this->_results);
     }
     }
 
 
     /**
     /**
@@ -487,19 +491,6 @@ class ResultSet implements ResultSetInterface
     }
     }
 
 
     /**
     /**
-     * Conditionally buffer the passed result
-     *
-     * @param array $result the result fetch from the database
-     * @return void
-     */
-    protected function _bufferResult($result)
-    {
-        if ($this->_useBuffering) {
-            $this->_results[$this->_index] = $result;
-        }
-    }
-
-    /**
      * Returns an array that can be used to describe the internal state of this
      * Returns an array that can be used to describe the internal state of this
      * object.
      * object.
      *
      *

+ 2 - 2
tests/TestCase/ORM/QueryTest.php

@@ -997,9 +997,9 @@ class QueryTest extends TestCase
             '\Database\StatementInterface',
             '\Database\StatementInterface',
             ['fetch', 'closeCursor', 'rowCount']
             ['fetch', 'closeCursor', 'rowCount']
         );
         );
-        $statement->expects($this->exactly(3))
+        $statement->expects($this->exactly(2))
             ->method('fetch')
             ->method('fetch')
-            ->will($this->onConsecutiveCalls(['a' => 1], ['a' => 2], false));
+            ->will($this->onConsecutiveCalls(['a' => 1], ['a' => 2]));
 
 
         $statement->expects($this->once())
         $statement->expects($this->once())
             ->method('rowCount')
             ->method('rowCount')