Skip to content

Commit b0f23d2

Browse files
committed
auto increment in mysql psv :
example: [user|auto-increment:123] This does not work yet for sqllite
1 parent 125f925 commit b0f23d2

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/TestDbAcle/Db/DataInserter/DataInserter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function processTable(\TestDbAcle\Psv\Table\Table $table)
4646
if(!$table->getMeta()->isReplaceMode() && !$table->getMeta()->isAppendMode()){
4747
$this->pdoFacade->clearTable($table->getName());
4848
}
49+
if($autoIncrement = $table->getMeta()->getAutoIncrement()){
50+
$this->pdoFacade->setAutoIncrement($table->getName(), $autoIncrement);
51+
}
4952
foreach ($table->toArray() as $valuesToBeInserted) {
5053
$this->insertValues($this->upsertBuilderFactory->getUpserter($table, $this->tableList->getTable($table->getName()), $valuesToBeInserted), $valuesToBeInserted);
5154
}

lib/TestDbAcle/Psv/Table/Meta.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function isAppendMode()
4343
return $this->getAttribute('mode') == 'append';
4444
}
4545

46+
public function getAutoIncrement()
47+
{
48+
return $this->getAttribute('auto-increment');
49+
}
50+
4651
public function getIdentifyColumns()
4752
{
4853
return (array) $this->getAttribute('identifiedBy', array());

tests/Functional/tests/SmokeTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ function test_SetupCanAppendData()
130130
", array('NOW'=>date("Y-m-d")));
131131
}
132132

133+
/**
134+
* @covers \TestDbAcle\Commands\FilterTableStateByPsvCommand::execute()
135+
* @covers \TestDbAcle\Commands\FilterTableStateByPsvCommand::FilterTableStateByPsvCommand()
136+
* @covers \TestDbAcle\Commands\FilterTableStateByPsvCommand::SetAutoIncrementCommand()
137+
* @covers \TestDbAcle::getDefaultFactories()
138+
*/
139+
function test_SetAutoIncrement()
140+
{
141+
142+
$this->setupTables("
143+
144+
[user|auto-increment:123]
145+
146+
");
147+
148+
$this->getPdo()->exec("insert into user (name) values('test')");
149+
150+
151+
$this->assertTableStateContains("
152+
[user]
153+
user_id |name
154+
123 |test
155+
");
156+
}
157+
133158
/**
134159
* @covers \TestDbAcle\Commands\FilterTableStateByPsvCommand::execute()
135160
* @covers \TestDbAcle\Commands\FilterTableStateByPsvCommand::FilterTableStateByPsvCommand()

0 commit comments

Comments
 (0)