public function DbCommandBaseTest::testPrefix in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest::testPrefix()
Test specifying a prefix for different connections.
File
- core/
modules/ system/ tests/ src/ Kernel/ Scripts/ DbCommandBaseTest.php, line 80 - Contains \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest.
Class
- DbCommandBaseTest
- Test that the DbToolsApplication works correctly.
Namespace
Drupal\Tests\system\Kernel\ScriptsCode
public function testPrefix() {
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())
->tablePrefix());
$connection_info = Database::getConnectionInfo('default')['default'];
$command_tester
->execute([
'-db-url' => $connection_info['driver'] . '://' . $connection_info['username'] . ':' . $connection_info['password'] . '@' . $connection_info['host'] . '/' . $connection_info['database'],
'--prefix' => 'extra2',
]);
$this
->assertEquals('extra2', $command
->getDatabaseConnection($command_tester
->getInput())
->tablePrefix());
// This breaks simpletest cleanup.
// $command_tester->execute([
// '--prefix' => 'notsimpletest',
// ]);
// $this->assertEquals('notsimpletest', $command->getDatabaseConnection($command_tester->getInput())->tablePrefix());
}