You are here

protected function DbDumpCommandTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php \Drupal\Tests\system\Kernel\Scripts\DbDumpCommandTest::setUp()
  2. 9 core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php \Drupal\Tests\system\Kernel\Scripts\DbDumpCommandTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php, line 25

Class

DbDumpCommandTest
Test that the DbDumpCommand works correctly.

Namespace

Drupal\Tests\system\Kernel\Scripts

Code

protected function setUp() : void {
  parent::setUp();

  // Determine what database backend is running, and set the skip flag.
  if (Database::getConnection()
    ->databaseType() !== 'mysql') {
    $this
      ->markTestSkipped("Skipping test since the DbDumpCommand is currently only compatible with MySQL");
  }

  // Rebuild the router to ensure a routing table.
  \Drupal::service('router.builder')
    ->rebuild();

  /** @var \Drupal\Core\Database\Connection $connection */
  $connection = $this->container
    ->get('database');
  $connection
    ->insert('router')
    ->fields([
    'name',
    'path',
    'pattern_outline',
  ])
    ->values([
    'test',
    'test',
    'test',
  ])
    ->execute();

  // Create a table with a field type not defined in
  // \Drupal\Core\Database\Schema::getFieldTypeMap.
  $table_name = $connection
    ->tablePrefix() . 'foo';
  $sql = "create table if not exists `{$table_name}` (`test` datetime NOT NULL);";
  $connection
    ->query($sql)
    ->execute();
}