-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #6167 - Forced SELECT NEXTVAL to be run on master #6168
Changes from 3 commits
f8e7cbd
a77d78f
ffaf00d
860de24
28c51ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Doctrine\Tests\Mocks; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver\Statement; | ||
|
||
/** | ||
* Mock class for Connection. | ||
|
@@ -13,6 +14,16 @@ class ConnectionMock extends Connection | |
*/ | ||
private $_fetchOneResult; | ||
|
||
/** | ||
* @var \Exception | ||
*/ | ||
private $_fetchOneException; | ||
|
||
/** | ||
* @var Statement | ||
*/ | ||
private $_queryResult; | ||
|
||
/** | ||
* @var DatabasePlatformMock | ||
*/ | ||
|
@@ -86,9 +97,21 @@ public function lastInsertId($seqName = null) | |
*/ | ||
public function fetchColumn($statement, array $params = array(), $colnum = 0, array $types = array()) | ||
{ | ||
if ($this->_fetchOneException != null) { | ||
throw $this->_fetchOneException; | ||
} | ||
|
||
return $this->_fetchOneResult; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function query() | ||
{ | ||
return $this->_queryResult; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -112,6 +135,16 @@ public function setFetchOneResult($fetchOneResult) | |
$this->_fetchOneResult = $fetchOneResult; | ||
} | ||
|
||
/** | ||
* @param \Exception $exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, update this docblock in order to reflect that this param also accepts |
||
* | ||
* @return void | ||
*/ | ||
public function setFetchOneException(\Exception $exception = null) | ||
{ | ||
$this->_fetchOneException = $exception; | ||
} | ||
|
||
/** | ||
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform | ||
* | ||
|
@@ -132,6 +165,14 @@ public function setLastInsertId($id) | |
$this->_lastInsertId = $id; | ||
} | ||
|
||
/** | ||
* @param Statement $result | ||
*/ | ||
public function setQueryResult($result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can |
||
{ | ||
$this->_queryResult = $result; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Doctrine\Tests\ORM\Id; | ||
|
||
use Doctrine\ORM\Id\SequenceGenerator; | ||
use Doctrine\Tests\Mocks\StatementArrayMock; | ||
use Doctrine\Tests\OrmTestCase; | ||
|
||
/** | ||
|
@@ -23,17 +24,20 @@ 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.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SPL |
||
); | ||
|
||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkurzeja please use short-array syntax here ;) |
||
$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()); | ||
} | ||
|
||
|
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use Yoda condition and strict comparison.