siteDirectory = $test_db->getTestSitePath(); $this->databasePrefix = $test_db->getDatabasePrefix(); } /** * Changes the database connection to the prefixed one. */ protected function changeDatabasePrefix() { if (empty($this->databasePrefix)) { $this->prepareDatabasePrefix(); } // If the test is run with argument dburl then use it. $db_url = getenv('SIMPLETEST_DB'); if (!empty($db_url)) { $database = Database::convertDbUrlToConnectionInfo($db_url, isset($this->root) ? $this->root : DRUPAL_ROOT); Database::addConnectionInfo('default', 'default', $database); } // Clone the current connection and replace the current prefix. $connection_info = Database::getConnectionInfo('default'); if (is_null($connection_info)) { throw new \InvalidArgumentException('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh.'); } else { Database::renameConnection('default', 'simpletest_original_default'); foreach ($connection_info as $target => $value) { // Replace the full table prefix definition to ensure that no table // prefixes of the test runner leak into the test. $connection_info[$target]['prefix'] = [ 'default' => $value['prefix']['default'] . $this->databasePrefix, ]; } Database::addConnectionInfo('default', 'default', $connection_info['default']); } } /** * Gets the config schema exclusions for this test. * * @return string[] * An array of config object names that are excluded from schema checking. */ protected function getConfigSchemaExclusions() { $class = get_class($this); $exceptions = []; while ($class) { if (property_exists($class, 'configSchemaCheckerExclusions')) { $exceptions = array_merge($exceptions, $class::$configSchemaCheckerExclusions); } $class = get_parent_class($class); } // Filter out any duplicates. return array_unique($exceptions); } }