function DbCommandBaseTest::testPrefix

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest::testPrefix()
  2. 8.9.x core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest::testPrefix()
  3. 10 core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest::testPrefix()

Tests specifying a prefix for different connections.

File

core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php, line 75

Class

DbCommandBaseTest
Test that the DbToolsApplication works correctly.

Namespace

Drupal\Tests\system\Kernel\Scripts

Code

public function testPrefix() : void {
    if (Database::getConnection()->driver() == 'sqlite') {
        $this->markTestSkipped('SQLITE modifies the prefixes so we cannot effectively test it');
    }
    Database::addConnectionInfo('magic_db', 'default', Database::getConnectionInfo('default')['default']);
    $command = new DbCommandBaseTester();
    $command_tester = new CommandTester($command);
    $command_tester->execute([
        '--database' => 'magic_db',
        '--prefix' => 'extra',
    ]);
    $this->assertEquals('extra', $command->getDatabaseConnection($command_tester->getInput())
        ->getPrefix());
    $command_tester->execute([
        '-db-url' => Database::getConnectionInfoAsUrl(),
        '--prefix' => 'extra2',
    ]);
    $this->assertEquals('extra2', $command->getDatabaseConnection($command_tester->getInput())
        ->getPrefix());
    // This breaks test cleanup.
    // @code
    //    $command_tester->execute([
    //      '--prefix' => 'notsimpletest',
    //    ]);
    //    $this->assertEquals('notsimpletest', $command->getDatabaseConnection($command_tester->getInput())->tablePrefix());
    // @endcode
}

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