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 @@
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use PDO;
......@@ -870,31 +869,27 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testIteratorCanBeIteratedMultipleTimes()
{
$preTestLogger = $this->_conn->getConfiguration()->getSQLLogger();
$stack = new DebugStack();
$this->_conn->getConfiguration()->setSQLLogger($stack);
$sql = 'SELECT test_int, test_string FROM fetch_table';
$sql = 'SELECT CURTIME(6) AS time_started, test_int, test_string FROM fetch_table';
$stmt = $this->_conn->query($sql);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$timeStartedMsFirstLoop = null;
$timeStartedMsSecondLoop = null;
$i = 0;
foreach ($stmt as $row) {
$timeStartedMsFirstLoop = $row['time_started'];
$i++;
}
$j = 0;
foreach ($stmt as $row2) {
$timeStartedMsSecondLoop = $row2['time_started'];
$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);
$this->assertEquals($timeStartedMsFirstLoop, $timeStartedMsSecondLoop);
}
}
......
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