Same filename in this branch
- 10 core/tests/Drupal/KernelTests/Core/Database/NextIdTest.php
- 10 core/modules/mysql/tests/src/Kernel/mysql/NextIdTest.php
Same filename and directory in other branches
- 9 core/modules/mysql/tests/src/Kernel/mysql/NextIdTest.php
Namespace
Drupal\Tests\mysql\Kernel\mysql
File
core/modules/mysql/tests/src/Kernel/mysql/NextIdTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\mysql\Kernel\mysql;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;
class NextIdTest extends DriverSpecificDatabaseTestBase {
protected static $modules = [
'database_test',
'system',
];
protected function setUp() : void {
parent::setUp();
$table_specification = [
'description' => 'Stores IDs.',
'fields' => [
'value' => [
'description' => 'The value of the sequence.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
'primary key' => [
'value',
],
];
$this->connection
->schema()
->createTable('sequences', $table_specification);
}
public function testDbNextIdClosedConnection() {
$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');
$this
->expectDeprecation('Drupal\\mysql\\Driver\\Database\\mysql\\Connection::nextIdDelete() 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');
$connection_info = Database::getConnectionInfo();
Database::addConnectionInfo('default', 'next_id', $connection_info['default']);
Database::getConnection('next_id')
->nextId();
Database::getConnection('next_id')
->nextId();
$count = $this->connection
->select('sequences')
->countQuery()
->execute()
->fetchField();
$this
->assertGreaterThan(1, $count);
Database::closeConnection('next_id');
$count = $this->connection
->select('sequences')
->countQuery()
->execute()
->fetchField();
$this
->assertEquals(1, $count);
}
}
Classes