Skip to content

Commit

Permalink
add unit tests to check lastInsertId
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed May 16, 2015
1 parent 0134587 commit 94acb2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/framework/db/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ public function testIntegrityViolation()
$command->execute();
}

public function testLastInsertId()
{
$db = $this->getConnection();

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID());
}

public function testQueryCache()
{
$db = $this->getConnection();
Expand Down
10 changes: 10 additions & 0 deletions tests/framework/db/oci/OracleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ public function testAutoQuoting()
$command = $db->createCommand($sql);
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
}

public function testLastInsertId()
{
$db = $this->getConnection();

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_SEQ'));
}
}
10 changes: 10 additions & 0 deletions tests/framework/db/pgsql/PostgreSQLCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public function testBooleanValuesBatchInsert()
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;');
$this->assertEquals(1, $command->queryScalar());
}

public function testLastInsertId()
{
$db = $this->getConnection();

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_id_seq'));
}
}

0 comments on commit 94acb2e

Please sign in to comment.