Skip to content
Permalink
Browse files

added exception for serialize an unbuffered result set, and also a te…

…st for this edge case
  • Loading branch information...
thinkingmedia
thinkingmedia committed Jan 30, 2017
1 parent 434ea31 commit 80e0994b62746a285221a61ffca7d9a0aaab28b9
Showing with 15 additions and 1 deletion.
  1. +5 −0 src/ORM/ResultSet.php
  2. +10 −1 tests/TestCase/ORM/ResultSetTest.php
@@ -313,6 +313,11 @@ public function first()
*/
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();
}
@@ -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;
@@ -111,6 +110,16 @@ public function testSerialization()
$this->assertEquals($expected, $outcome->toArray());
}
/**
* @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
*

0 comments on commit 80e0994

Please sign in to comment.
You can’t perform that action at this time.