getConnectionInfoAsUrl example


  public function runCommand(array $unescaped_test_classnames, string $phpunit_file, int &$status = NULL, array &$output = NULL): string {
    global $base_url;
    // Setup an environment variable containing the database connection so that     // functional tests can connect to the database.     putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());

    // Setup an environment variable containing the base URL, if it is available.     // This allows functional tests to browse the site under test. When running     // tests via CLI, core/phpunit.xml.dist or core/scripts/run-tests.sh can set     // this variable.     if ($base_url) {
      putenv('SIMPLETEST_BASE_URL=' . $base_url);
      putenv('BROWSERTEST_OUTPUT_DIRECTORY=' . $this->workingDirectory);
    }
    $phpunit_bin = $this->phpUnitCommand();

    
'foo://bar:baz@test1', 'test2', "Can not convert 'foo://bar:baz@test1' to a database connection, class 'Drupal\\Driver\\Database\\foo\\Connection' does not exist"],
    ];
  }

  /** * @covers ::getConnectionInfoAsUrl * * @dataProvider providerGetConnectionInfoAsUrl */
  public function testGetConnectionInfoAsUrl(array $info$expected_url) {
    Database::addConnectionInfo('default', 'default', $info);
    $url = Database::getConnectionInfoAsUrl();
    $this->assertEquals($expected_url$url);
  }

  /** * Data provider for testGetConnectionInfoAsUrl(). * * @return array * Array of arrays with the following elements: * - An array mocking the database connection info. Possible keys are * database, username, password, prefix, host, port, namespace and driver. * - The expected URL after conversion. */
$this->expectException(ConnectionNotDefinedException::class);
    $command->getDatabaseConnection($command_tester->getInput());
  }

  /** * Tests supplying database connection as a URL. */
  public function testSpecifyDbUrl() {
    $command = new DbCommandBaseTester();
    $command_tester = new CommandTester($command);
    $command_tester->execute([
      '-db-url' => Database::getConnectionInfoAsUrl(),
    ]);
    $this->assertEquals('db-tools', $command->getDatabaseConnection($command_tester->getInput())->getKey());

    Database::removeConnection('db-tools');
    $command_tester->execute([
      '--database-url' => Database::getConnectionInfoAsUrl(),
    ]);
    $this->assertEquals('db-tools', $command->getDatabaseConnection($command_tester->getInput())->getKey());
  }

  /** * Tests specifying a prefix for different connections. */
Home | Imprint | This part of the site doesn't use cookies.