diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index 513d46d..45c8c54 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -238,6 +238,32 @@ function simpletest_phpunit_configuration_filepath() {
* The results as returned by exec().
*/
function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file) {
+ // Set the up an environment variable containing the database connection so
+ // that functional tests can connect to the database.
+ $db_info = Database::getConnectionInfo();
+ if ($db_info['default']['driver'] == 'sqlite') {
+ $db_url = $db_info['default']['driver'] . '://localhost/' . $db_info['default']['database'];
+ }
+ else {
+ $user = '';
+ if ($db_info['default']['username']) {
+ $user = $db_info['default']['username'];
+ if ($db_info['default']['password']) {
+ $user .= ':' . $db_info['default']['password'];
+ }
+ $user .= '@';
+ }
+
+ $db_url = $db_info['default']['driver'] . '://' . $user . $db_info['default']['host'];
+ if (isset($db_info['default']['port'])) {
+ $db_url .= ':' . $db_info['default']['port'];
+ }
+ $db_url .= '/' . $db_info['default']['database'];
+ }
+ if ($db_info['default']['prefix']['default']) {
+ $db_url .= '#' . $db_info['default']['prefix']['default'];
+ }
+ putenv('SIMPLETEST_DB=' . $db_url);
$phpunit_bin = simpletest_phpunit_command();
$command = array(
@@ -273,6 +299,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
// via the simpletest UI.
$ret = exec(join($command, " "));
chdir($old_cwd);
+ putenv('SIMPLETEST_DB=');
return $ret;
}
diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php
index 443ece8..e457fe4 100644
--- a/core/modules/simpletest/src/BrowserTestBase.php
+++ b/core/modules/simpletest/src/BrowserTestBase.php
@@ -32,6 +32,9 @@
* Test case for typical Drupal tests.
*
* @ingroup testing
+ *
+ * All BrowserTestBase tests must have the @runTestsInSeparateProcesses
+ * annotation to ensure process isolation.
*/
abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
@@ -1060,15 +1063,49 @@ private function changeDatabasePrefix() {
// Clone the current connection and replace the current prefix.
$connection_info = Database::getConnectionInfo('default');
- 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'] = array(
- 'default' => $value['prefix']['default'] . $this->databasePrefix,
+ if (is_null($connection_info)) {
+ $db_url = getenv('SIMPLETEST_DB');
+ $info = parse_url($db_url);
+ if (!isset($info['scheme'], $info['host'], $info['path'])) {
+ throw new Wobbly();
+ }
+ $info += array(
+ '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'];
+ }
+ $database = array(
+ 'driver' => $info['scheme'],
+ 'username' => $info['user'],
+ 'password' => $info['pass'],
+ 'host' => $info['host'],
+ 'database' => $info['path'],
+ 'prefix' => array(
+ 'default' => $this->databasePrefix,
+ ),
);
+ if (isset($info['port'])) {
+ $database['port'] = $info['port'];
+ }
+ Database::addConnectionInfo('default', 'default', $database);
+ }
+ 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'] = array(
+ 'default' => $value['prefix']['default'] . $this->databasePrefix,
+ );
+ }
+ Database::addConnectionInfo('default', 'default', $connection_info['default']);
}
- Database::addConnectionInfo('default', 'default', $connection_info['default']);
}
/**
diff --git a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
index 6f4c473..99194c5 100755
--- a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
+++ b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php
@@ -14,6 +14,8 @@
*
* @group simpletest
* @group modern
+ *
+ * @runTestsInSeparateProcesses
*/
class BrowserTestBaseTest extends BrowserTestBase {
diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index 5a9a23f..44bbc33 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -7,6 +7,7 @@
+
@@ -18,18 +19,16 @@
./vendor
./drush/tests
-
- ./modules/config/tests/config_test/src
- ./modules/*/tests/src/Functional
./tests/Drupal/FunctionalTests
+ ./modules/*/tests/src/Functional
+ ../modules/*/tests/src/Functional
+ ../sites/*/modules/*/tests/src/Functional
./vendor
./drush/tests
-
- ./modules/config/tests/config_test/src