#6167 - fixed tests and added info why query is used in SequenceGenerator
This commit is contained in:
parent
60b6073643
commit
edffb4d449
@ -76,7 +76,8 @@ class SequenceGenerator extends AbstractIdGenerator implements Serializable
|
|||||||
$conn = $em->getConnection();
|
$conn = $em->getConnection();
|
||||||
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
|
$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;
|
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\Mocks;
|
namespace Doctrine\Tests\Mocks;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Doctrine\DBAL\Driver\Statement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock class for Connection.
|
* Mock class for Connection.
|
||||||
@ -13,6 +14,11 @@ class ConnectionMock extends Connection
|
|||||||
*/
|
*/
|
||||||
private $_fetchOneResult;
|
private $_fetchOneResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Statement
|
||||||
|
*/
|
||||||
|
private $_queryResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DatabasePlatformMock
|
* @var DatabasePlatformMock
|
||||||
*/
|
*/
|
||||||
@ -89,6 +95,14 @@ class ConnectionMock extends Connection
|
|||||||
return $this->_fetchOneResult;
|
return $this->_fetchOneResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function query()
|
||||||
|
{
|
||||||
|
return $this->_queryResult;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -132,6 +146,14 @@ class ConnectionMock extends Connection
|
|||||||
$this->_lastInsertId = $id;
|
$this->_lastInsertId = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Statement $result
|
||||||
|
*/
|
||||||
|
public function setQueryResult($result)
|
||||||
|
{
|
||||||
|
$this->_queryResult = $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Doctrine\Tests\ORM\Id;
|
namespace Doctrine\Tests\ORM\Id;
|
||||||
|
|
||||||
use Doctrine\ORM\Id\SequenceGenerator;
|
use Doctrine\ORM\Id\SequenceGenerator;
|
||||||
|
use Doctrine\Tests\Mocks\StatementArrayMock;
|
||||||
use Doctrine\Tests\OrmTestCase;
|
use Doctrine\Tests\OrmTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,15 +26,14 @@ class SequenceGeneratorTest extends OrmTestCase
|
|||||||
{
|
{
|
||||||
for ($i=0; $i < 42; ++$i) {
|
for ($i=0; $i < 42; ++$i) {
|
||||||
if ($i % 10 == 0) {
|
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);
|
$id = $this->_seqGen->generate($this->_em, null);
|
||||||
$this->assertEquals($i, $id);
|
$this->assertEquals($i, $id);
|
||||||
$this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue());
|
$this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue());
|
||||||
$this->assertEquals($i + 1, $this->_seqGen->getNextValue());
|
$this->assertEquals($i + 1, $this->_seqGen->getNextValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user