diff --git a/src/TableGateway/Feature/SequenceFeature.php b/src/TableGateway/Feature/SequenceFeature.php index 3c72fd3b6f..c6b8f8eb2b 100644 --- a/src/TableGateway/Feature/SequenceFeature.php +++ b/src/TableGateway/Feature/SequenceFeature.php @@ -117,7 +117,7 @@ public function lastSequenceId() $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.CURRVAL as "currval" FROM dual'; break; case 'PostgreSQL': - $sql = 'SELECT CURRVAL(\'' . $this->sequenceName . '\')'; + $sql = 'SELECT CURRVAL(\'"' . $this->sequenceName . '"\')'; break; default : return; diff --git a/test/TableGateway/Feature/FeatureSetTest.php b/test/TableGateway/Feature/FeatureSetTest.php index bfc6271c17..90098978db 100644 --- a/test/TableGateway/Feature/FeatureSetTest.php +++ b/test/TableGateway/Feature/FeatureSetTest.php @@ -140,7 +140,7 @@ public function testCallMagicCallSucceedsForValidMethodOfAddedFeature() $statementMock = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface'); $statementMock->expects($this->any()) ->method('prepare') - ->with('SELECT CURRVAL(\'' . $sequenceName . '\')'); + ->with('SELECT CURRVAL(\'"' . $sequenceName . '"\')'); $statementMock->expects($this->any()) ->method('execute') ->will($this->returnValue($resultMock)); diff --git a/test/TableGateway/Feature/SequenceFeatureTest.php b/test/TableGateway/Feature/SequenceFeatureTest.php index b3edc59c33..2670e20f3a 100644 --- a/test/TableGateway/Feature/SequenceFeatureTest.php +++ b/test/TableGateway/Feature/SequenceFeatureTest.php @@ -71,4 +71,45 @@ public function nextSequenceIdProvider() return [['PostgreSQL', 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')'], ['Oracle', 'SELECT ' . $this->sequenceName . '.NEXTVAL as "nextval" FROM dual']]; } + + /** + * @dataProvider lastSequenceIdProvider + */ + public function testLastSequenceId($platformName, $statementSql) + { + $platform = $this->getMockForAbstractClass('Zend\Db\Adapter\Platform\PlatformInterface', ['getName']); + $platform->expects($this->any()) + ->method('getName') + ->will($this->returnValue($platformName)); + $platform->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnValue($this->sequenceName)); + $adapter = $this->getMock('Zend\Db\Adapter\Adapter', ['getPlatform', 'createStatement'], [], '', false); + $adapter->expects($this->any()) + ->method('getPlatform') + ->will($this->returnValue($platform)); + $result = $this->getMockForAbstractClass('Zend\Db\Adapter\Driver\ResultInterface', [], '', false, true, true, ['current']); + $result->expects($this->any()) + ->method('current') + ->will($this->returnValue(['currval' => 1])); + $statement = $this->getMockForAbstractClass('Zend\Db\Adapter\Driver\StatementInterface', [], '', false, true, true, ['prepare', 'execute']); + $statement->expects($this->any()) + ->method('execute') + ->will($this->returnValue($result)); + $statement->expects($this->any()) + ->method('prepare') + ->with($statementSql); + $adapter->expects($this->once()) + ->method('createStatement') + ->will($this->returnValue($statement)); + $this->tableGateway = $this->getMockForAbstractClass('Zend\Db\TableGateway\TableGateway', ['table', $adapter], '', true); + $this->feature->setTableGateway($this->tableGateway); + $this->feature->lastSequenceId(); + } + + public function lastSequenceIdProvider() + { + return [['PostgreSQL', 'SELECT CURRVAL(\'"' . $this->sequenceName . '"\')'], + ['Oracle', 'SELECT ' . $this->sequenceName . '.CURRVAL as "currval" FROM dual']]; + } }