function InsertTest::testInsertLastInsertID

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertLastInsertID()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertLastInsertID()
  3. 10 core/tests/Drupal/KernelTests/Core/Database/InsertTest.php \Drupal\KernelTests\Core\Database\InsertTest::testInsertLastInsertID()

Tests that inserts return the proper auto-increment ID.

File

core/tests/Drupal/KernelTests/Core/Database/InsertTest.php, line 143

Class

InsertTest
Tests the insert builder.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testInsertLastInsertID() : void {
    $id = $this->connection
        ->insert('test')
        ->fields([
        'name' => 'Larry',
        'age' => '30',
    ])
        ->execute();
    $this->assertSame('5', $id, 'Auto-increment ID returned successfully.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.