Commit abbedeca authored by Ian Jenkins's avatar Ian Jenkins

Check query is only run once during iteration.

parent 689200e4
...@@ -16,8 +16,6 @@ class RewindableGenerator implements \IteratorAggregate ...@@ -16,8 +16,6 @@ class RewindableGenerator implements \IteratorAggregate
public function getIterator() public function getIterator()
{ {
$g = $this->generator; return ($this->generator)();
return $g();
} }
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional; namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use PDO; use PDO;
...@@ -869,7 +870,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -869,7 +870,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testIteratorCanBeIteratedMultipleTimes() public function testIteratorCanBeIteratedMultipleTimes()
{ {
$sql = "SELECT test_int, test_string FROM fetch_table"; $preTestLogger = $this->_conn->getConfiguration()->getSQLLogger();
$stack = new DebugStack();
$this->_conn->getConfiguration()->setSQLLogger($stack);
$sql = 'SELECT test_int, test_string FROM fetch_table';
$stmt = $this->_conn->query($sql); $stmt = $this->_conn->query($sql);
$stmt->setFetchMode(\PDO::FETCH_ASSOC); $stmt->setFetchMode(\PDO::FETCH_ASSOC);
...@@ -884,6 +889,12 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -884,6 +889,12 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
} }
$this->assertEquals($i, $j); $this->assertEquals($i, $j);
// Check only 1 query is run.
$this->assertCount(1, $stack->queries);
// Reset the SQL logger
$this->_conn->getConfiguration()->setSQLLogger($preTestLogger);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment