NextIdTest.php

Same filename in other branches
  1. 9 core/modules/mysql/tests/src/Kernel/mysql/NextIdTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php
  3. 10 core/modules/mysql/tests/src/Kernel/mysql/NextIdTest.php
  4. 10 core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php

Namespace

Drupal\KernelTests\Core\Database

File

core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php

View source
<?php

namespace Drupal\KernelTests\Core\Database;


/**
 * Tests the sequences API.
 *
 * @group Database
 */
class NextIdTest extends DatabaseTestBase {
    
    /**
     * The modules to enable.
     *
     * @var array
     */
    public static $modules = [
        'database_test',
        'system',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() {
        parent::setUp();
        $this->installSchema('system', 'sequences');
    }
    
    /**
     * Tests that the sequences API works.
     */
    public function testDbNextId() {
        $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->assertEqual($first + 1, $second, 'The second call from a sequence provides a number increased by one.');
        $result = $this->connection
            ->nextId(1000);
        $this->assertEqual($result, 1001, 'Sequence provides a larger number than the existing ID.');
    }

}

Classes

Title Deprecated Summary
NextIdTest Tests the sequences API.

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