Skip to content

Commit

Permalink
zendframework#186 missing last sequence id test.
Browse files Browse the repository at this point in the history
  • Loading branch information
alextech committed Dec 25, 2016
1 parent ce3b28c commit 7e7d3df
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/TableGateway/Feature/SequenceFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ public function testNextSequenceIdByPlatform($platform, $statementSql, $statemen
$feature->nextSequenceId();
}


/**
* @dataProvider lastSequenceIdProvider
*/
public function testLastSequenceIdByPlatform($platform, $statementSql, $statementParameter)
{
$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')
->with($statementParameter)
->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);

$feature = new SequenceFeature($this->primaryKeyField, $this->sequenceName);
$feature->setTableGateway($this->tableGateway);
$feature->lastSequenceId();
}

public function testDoNotReactToDifferentColumnName() {
$sequence1 = new SequenceFeature('col_1', 'seq_1');
$this->assertEquals($sequence1->lastSequenceId('col_2'), null, 'Sequence should not react to foreign column name');
Expand All @@ -129,6 +161,14 @@ public function nextSequenceIdProvider()
];
}

public function lastSequenceIdProvider()
{
return [
[new TrustingPostgresqlPlatform(), 'SELECT CURRVAL( :sequence_name )', ['sequence_name' => $this->sequenceName]],
[new TrustingOraclePlatform(), 'SELECT "' . $this->sequenceName . '".CURRVAL as "currval" FROM dual', []]
];
}

public function tableIdentifierProvider()
{
return [
Expand Down

0 comments on commit 7e7d3df

Please sign in to comment.