Commit 0ebafdbb authored by Ian Jenkins's avatar Ian Jenkins

Compare two timestamps to ensure only one query is run when iterating.

parent abbedeca
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
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;
...@@ -870,31 +869,27 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -870,31 +869,27 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testIteratorCanBeIteratedMultipleTimes() public function testIteratorCanBeIteratedMultipleTimes()
{ {
$preTestLogger = $this->_conn->getConfiguration()->getSQLLogger(); $sql = 'SELECT CURTIME(6) AS time_started, test_int, test_string FROM fetch_table';
$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);
$timeStartedMsFirstLoop = null;
$timeStartedMsSecondLoop = null;
$i = 0; $i = 0;
foreach ($stmt as $row) { foreach ($stmt as $row) {
$timeStartedMsFirstLoop = $row['time_started'];
$i++; $i++;
} }
$j = 0; $j = 0;
foreach ($stmt as $row2) { foreach ($stmt as $row2) {
$timeStartedMsSecondLoop = $row2['time_started'];
$j++; $j++;
} }
$this->assertEquals($i, $j); $this->assertEquals($i, $j);
$this->assertEquals($timeStartedMsFirstLoop, $timeStartedMsSecondLoop);
// 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