Skip to content

Commit

Permalink
#6167 - tests - throw exception if wrong method used to get sequence …
Browse files Browse the repository at this point in the history
…nextval
  • Loading branch information
mkurzeja authored and Ocramius committed Jun 21, 2017
1 parent edffb4d commit 71b040c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/Doctrine/Tests/Mocks/ConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class ConnectionMock extends Connection
*/
private $_fetchOneResult;

/**
* @var \Exception
*/
private $_fetchOneException;

/**
* @var Statement
*/
Expand Down Expand Up @@ -92,6 +97,10 @@ public function lastInsertId($seqName = null)
*/
public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = [])
{
if ($this->_fetchOneException != null) {
throw $this->_fetchOneException;
}

return $this->_fetchOneResult;
}

Expand Down Expand Up @@ -126,6 +135,16 @@ public function setFetchOneResult($fetchOneResult)
$this->_fetchOneResult = $fetchOneResult;
}

/**
* @param \Exception $exception
*
* @return void
*/
public function setFetchOneException(\Exception $exception = null)
{
$this->_fetchOneException = $exception;
}

/**
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*
Expand Down
4 changes: 4 additions & 0 deletions tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ protected function setUp()

public function testGeneration()
{
$this->_em->getConnection()->setFetchOneException(
new \Exception('Fetch* method used. Query method should be used instead, as NEXTVAL should be run on a master server in master-slave setup.')
);

for ($i=0; $i < 42; ++$i) {
if ($i % 10 == 0) {
$nextId = array(array((int)($i / 10) * 10));
Expand Down

0 comments on commit 71b040c

Please sign in to comment.