1
0
mirror of synced 2025-02-02 21:41:45 +03:00

#6167 - fixed tests and added info why query is used in SequenceGenerator

This commit is contained in:
Michał Kurzeja 2016-12-12 07:45:25 +01:00 committed by Marco Pivetta
parent 60b6073643
commit edffb4d449
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629
3 changed files with 27 additions and 4 deletions

View File

@ -76,7 +76,8 @@ class SequenceGenerator extends AbstractIdGenerator implements Serializable
$conn = $em->getConnection();
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
$this->_nextValue = (int) $conn->query($sql)->fetchColumn(0);
// Use query to force master in MasterSlaveConnection
$this->_nextValue = (int) $conn->query($sql)->fetchColumn();
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
}

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\Mocks;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Statement;
/**
* Mock class for Connection.
@ -13,6 +14,11 @@ class ConnectionMock extends Connection
*/
private $_fetchOneResult;
/**
* @var Statement
*/
private $_queryResult;
/**
* @var DatabasePlatformMock
*/
@ -89,6 +95,14 @@ class ConnectionMock extends Connection
return $this->_fetchOneResult;
}
/**
* {@inheritdoc}
*/
public function query()
{
return $this->_queryResult;
}
/**
* {@inheritdoc}
*/
@ -132,6 +146,14 @@ class ConnectionMock extends Connection
$this->_lastInsertId = $id;
}
/**
* @param Statement $result
*/
public function setQueryResult($result)
{
$this->_queryResult = $result;
}
/**
* @return array
*/

View File

@ -3,6 +3,7 @@
namespace Doctrine\Tests\ORM\Id;
use Doctrine\ORM\Id\SequenceGenerator;
use Doctrine\Tests\Mocks\StatementArrayMock;
use Doctrine\Tests\OrmTestCase;
/**
@ -25,15 +26,14 @@ class SequenceGeneratorTest extends OrmTestCase
{
for ($i=0; $i < 42; ++$i) {
if ($i % 10 == 0) {
$this->_em->getConnection()->setFetchOneResult((int)($i / 10) * 10);
$nextId = array(array((int)($i / 10) * 10));
$this->_em->getConnection()->setQueryResult(new StatementArrayMock($nextId));
}
$id = $this->_seqGen->generate($this->_em, null);
$this->assertEquals($i, $id);
$this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue());
$this->assertEquals($i + 1, $this->_seqGen->getNextValue());
}
}
}