You are here

public function DbCommandBaseTest::testSpecifyDbUrl in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest::testSpecifyDbUrl()

Test supplying database connection as a url.

File

core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php, line 60
Contains \Drupal\Tests\system\Kernel\Scripts\DbCommandBaseTest.

Class

DbCommandBaseTest
Test that the DbToolsApplication works correctly.

Namespace

Drupal\Tests\system\Kernel\Scripts

Code

public function testSpecifyDbUrl() {
  $connection_info = Database::getConnectionInfo('default')['default'];
  $command = new DbCommandBaseTester();
  $command_tester = new CommandTester($command);
  $command_tester
    ->execute([
    '-db-url' => $connection_info['driver'] . '://' . $connection_info['username'] . ':' . $connection_info['password'] . '@' . $connection_info['host'] . '/' . $connection_info['database'],
  ]);
  $this
    ->assertEquals('db-tools', $command
    ->getDatabaseConnection($command_tester
    ->getInput())
    ->getKey());
  Database::removeConnection('db-tools');
  $command_tester
    ->execute([
    '--database-url' => $connection_info['driver'] . '://' . $connection_info['username'] . ':' . $connection_info['password'] . '@' . $connection_info['host'] . '/' . $connection_info['database'],
  ]);
  $this
    ->assertEquals('db-tools', $command
    ->getDatabaseConnection($command_tester
    ->getInput())
    ->getKey());
}