summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-08 09:40:20 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-12-08 09:40:20 +0100
commitf2c7acb3c065c35a1e75d512d0ce193f1989296f (patch)
tree4c3cec0c14b0ea0b1f0cb092515d112cafd13ec9 /tests
parent736e133c047a22b587294a1231b61ac2575f3f83 (diff)
downloadnextcloud-server-f2c7acb3c065c35a1e75d512d0ce193f1989296f.tar.gz
nextcloud-server-f2c7acb3c065c35a1e75d512d0ce193f1989296f.zip
Allow getting the last insert id without much hassle
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/db/querybuilder/querybuildertest.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php
index ca3901ad049..828a860ee80 100644
--- a/tests/lib/db/querybuilder/querybuildertest.php
+++ b/tests/lib/db/querybuilder/querybuildertest.php
@@ -1086,6 +1086,31 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
+ public function testGetLastInsertId() {
+ $qB = $this->connection->getQueryBuilder();
+
+ try {
+ $qB->getLastInsertId();
+ $this->fail('getLastInsertId() should throw an exception, when being called before insert()');
+ } catch (\BadMethodCallException $e) {
+ $this->assertTrue(true);
+ }
+
+ $qB->insert('appconfig')
+ ->values([
+ 'appid' => $qB->expr()->literal('testFirstResult'),
+ 'configkey' => $qB->expr()->literal('testing' . 50),
+ 'configvalue' => $qB->expr()->literal(100 - 50),
+ ])
+ ->execute();
+
+ $actual = $qB->getLastInsertId();
+
+ $this->assertNotNull($actual);
+ $this->assertInternalType('int', $actual);
+ $this->assertEquals($this->connection->lastInsertId('*PREFIX*appconfig'), $actual);
+ }
+
public function dataGetTableName() {
return [
['*PREFIX*table', null, '`*PREFIX*table`'],