diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php index adddda1..96359ec 100644 --- a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php +++ b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php @@ -43,7 +43,7 @@ * * @var bool */ - protected $debug = TRUE; + protected $debug = FALSE; /** * Modules to enable. diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php index 95b81d5..e923a04 100644 --- a/core/tests/Drupal/Tests/KernelTestBase.php +++ b/core/tests/Drupal/Tests/KernelTestBase.php @@ -268,6 +268,38 @@ protected function bootEnvironment() { Database::setMultipleConnectionInfo($this->getDatabaseConnectionInfo()); } + protected function parseDbUrl($db_url) { + $info = parse_url($db_url); + if (!isset($info['scheme'], $info['host'], $info['path'])) { + throw new \InvalidArgumentException('Invalid dburl, . Minimum requirement: driver://host/database'); + } + $info += [ + 'user' => '', + 'pass' => '', + 'fragment' => '', + ]; + if ($info['path'][0] === '/') { + $info['path'] = substr($info['path'], 1); + } + if ($info['scheme'] === 'sqlite' && $info['path'][0] !== '/') { + $info['path'] = DRUPAL_ROOT . '/' . $info['path']; + } + $db_info = [ + 'driver' => $info['scheme'], + 'username' => $info['user'], + 'password' => $info['pass'], + 'host' => $info['host'], + 'database' => $info['path'], + 'prefix' => [ + 'default' => $info['fragment'], + ], + ]; + if (isset($info['port'])) { + $db_info['port'] = $info['port']; + } + return $db_info; + } + /** * Bootstraps a kernel for a test. */ @@ -401,6 +433,16 @@ protected function getDatabaseConnectionInfo() { 'default' => '', ), ); + + // Allow to specify a custom db_url. + if ($db_url = getenv('phpunit_dburl')) { + $databases['default']['default'] = $this->parseDbUrl($db_url); + + // In the case we don't use sqlite directly we need to generate a DB prefix. + $suffix = mt_rand(100000, 999999); + $this->databasePrefix = 'simpletest' . $suffix; + $databases['default']['default']['prefix'] = ['default' => $this->databasePrefix]; + } return $databases; }