Browse Source

added exception for serialize an unbuffered result set, and also a test for this edge case

thinkingmedia 9 years ago
parent
commit
80e0994b62
2 changed files with 15 additions and 1 deletions
  1. 5 0
      src/ORM/ResultSet.php
  2. 10 1
      tests/TestCase/ORM/ResultSetTest.php

+ 5 - 0
src/ORM/ResultSet.php

@@ -313,6 +313,11 @@ class ResultSet implements ResultSetInterface
      */
     public function serialize()
     {
+        if (!$this->_useBuffering) {
+            $msg = 'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
+            throw new Exception($msg);
+        }
+
         while ($this->valid()) {
             $this->next();
         }

+ 10 - 1
tests/TestCase/ORM/ResultSetTest.php

@@ -14,7 +14,6 @@
  */
 namespace Cake\Test\TestCase\ORM;
 
-use Cake\Core\Configure;
 use Cake\Core\Plugin;
 use Cake\Datasource\ConnectionManager;
 use Cake\ORM\Entity;
@@ -112,6 +111,16 @@ class ResultSetTest extends TestCase
     }
 
     /**
+     * @expectedException \Cake\Database\Exception
+     * @expectedExceptionMessage You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.
+     */
+    public function testSerializationUnbuffered()
+    {
+        $results = $this->table->find('all')->bufferResults(false)->all();
+        serialize($results);
+    }
+
+    /**
      * Test iteration after serialization
      *
      * @return void