From 71b040c8497bcf5f60c2ad120d5a8283e4e41bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurzeja?= Date: Mon, 12 Dec 2016 12:29:29 +0100 Subject: [PATCH] #6167 - tests - throw exception if wrong method used to get sequence nextval --- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 19 +++++++++++++++++++ .../Tests/ORM/Id/SequenceGeneratorTest.php | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 11d08d480..ba0be9ee4 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -14,6 +14,11 @@ class ConnectionMock extends Connection */ private $_fetchOneResult; + /** + * @var \Exception + */ + private $_fetchOneException; + /** * @var Statement */ @@ -92,6 +97,10 @@ class ConnectionMock extends Connection */ public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) { + if ($this->_fetchOneException != null) { + throw $this->_fetchOneException; + } + return $this->_fetchOneResult; } @@ -126,6 +135,16 @@ class ConnectionMock extends Connection $this->_fetchOneResult = $fetchOneResult; } + /** + * @param \Exception $exception + * + * @return void + */ + public function setFetchOneException(\Exception $exception = null) + { + $this->_fetchOneException = $exception; + } + /** * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index c87547934..b972d0640 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -24,6 +24,10 @@ class SequenceGeneratorTest extends OrmTestCase 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));