Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php \Drupal\KernelTests\Core\Database\NextIdTest::testDbNextId()
  2. 9 core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php \Drupal\KernelTests\Core\Database\NextIdTest::testDbNextId()

Tests that the sequences API works.

File

core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php, line 46

Class

NextIdTest
Tests the sequences API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDbNextId() {
  $this
    ->expectDeprecation('Drupal\\Core\\Database\\Connection::nextId() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Modules should use instead the keyvalue storage for the last used id. See https://www.drupal.org/node/3349345');
  $first = $this->connection
    ->nextId();
  $second = $this->connection
    ->nextId();

  // We can test for exact increase in here because we know there is no
  // other process operating on these tables -- normally we could only
  // expect $second > $first.
  $this
    ->assertEquals($first + 1, $second, 'The second call from a sequence provides a number increased by one.');
  $result = $this->connection
    ->nextId(1000);
  $this
    ->assertEquals(1001, $result, 'Sequence provides a larger number than the existing ID.');
}