diff --git a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
index 8556561..2389dad 100644
--- a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
@@ -34,12 +34,10 @@ protected function alterRoutes(RouteCollection $collection) {
       '_form',
     );
 
-    foreach ($collection->all() as $route) {
+    foreach ($collection->all() as $name => $route) {
       if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) {
-        $placeholders = array('@variables' => implode(', ', $not_allowed_variables));
-        drupal_set_message(String::format('The following variables are reserved names by drupal: @variables', $placeholders));
-        watchdog('error', 'The following variables are reserved names by drupal: @variables', $placeholders);
-        return FALSE;
+        $reserved = implode(', ', $not_allowed_variables);
+        throw new \LogicException(sprintf('Route %s uses reserved variable names: %s', $name, $reserved));
       }
     }
     return TRUE;
diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
index 0457458..e772697 100644
--- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -136,7 +136,14 @@ public function scan($type, $include_tests = NULL) {
     }
 
     // Search the site-specific directory.
-    $searchdirs[static::ORIGIN_SITE] = conf_path();
+    // When called from PHPUnit bootstrap.php, conf_path() does not and should
+    // not exist.
+    if (function_exists('conf_path')) {
+      $searchdirs[static::ORIGIN_SITE] = conf_path();
+    }
+    else {
+      $searchdirs[static::ORIGIN_SITE] = 'sites/default';
+    }
 
     // Unless an explicit value has been passed, manually check whether we are
     // in a test environment, in which case test extensions must be included.
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
index cdab44f..a5e5230 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
@@ -5,7 +5,7 @@
  * Contains \Drupal\Tests\Core\EventSubscriber\SpecialAttributesRouteSubscriberTest.
  */
 
-namespace Drupal\Tests\Core\EventSubscriber {
+namespace Drupal\Tests\Core\EventSubscriber;
 
 use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
 use Drupal\Core\Routing\RouteBuildEvent;
@@ -95,25 +95,13 @@ public function testOnRouteBuildingValidVariables(Route $route) {
    *   The route to check.
    *
    * @dataProvider providerTestOnRouteBuildingInvalidVariables
+   * @expectedException \LogicException
    */
   public function testOnRouteBuildingInvalidVariables(Route $route) {
     $route_collection = new RouteCollection();
     $route_collection->add('test', $route);
     $event = new RouteBuildEvent($route_collection, 'test');
-    $this->assertFalse($this->specialAttributesRouteSubscriber->onAlterRoutes($event));
+    $this->specialAttributesRouteSubscriber->onAlterRoutes($event);
   }
 
 }
-
-}
-
-namespace {
-  if (!function_exists('watchdog')) {
-    function watchdog($type, $message, array $args = array()) {
-    }
-  }
-  if (!function_exists('drupal_set_message')) {
-    function drupal_set_message($type = NULL, $message = '') {
-    }
-  }
-}
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index 99fe34d..5c89887 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -2,88 +2,24 @@
 
 /**
  * @file
- * Autoloader for Drupal PHPUnit testing.
+ * Autoloader for Drupal PHPUnit tests.
  *
  * @see phpunit.xml.dist
  */
 
-/**
- * Finds all valid extension directories recursively within a given directory.
- *
- * @param string $scan_directory
- *   The directory that should be recursively scanned.
- * @return array
- *   An associative array of extension directories found within the scanned
- *   directory, keyed by extension name.
- */
-function drupal_phpunit_find_extension_directories($scan_directory) {
-  $extensions = array();
-  $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
-  foreach ($dirs as $dir) {
-    if (strpos($dir->getPathname(), 'info.yml') !== FALSE) {
-      // Cut off ".info.yml" from the filename for use as the extension name.
-      $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo()->getRealPath();
-    }
-  }
-  return $extensions;
-}
-
-/**
- * Returns directories under which contributed extensions may exist.
- *
- * @return array
- *   An array of directories under which contributed extensions may exist.
- */
-function drupal_phpunit_contrib_extension_directory_roots() {
-  $sites_path = __DIR__ . '/../../sites';
-  $paths = array();
-  // Note this also checks sites/../modules and sites/../profiles.
-  foreach (scandir($sites_path) as $site) {
-    $path = "$sites_path/$site";
-    $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL;
-    $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL;
-  }
-  return array_filter($paths);
-}
+use Drupal\simpletest\TestDiscovery;
 
-/**
- * Registers the namespace for each extension directory with the autoloader.
- *
- * @param Composer\Autoload\ClassLoader $loader
- *   The supplied autoloader.
- * @param array $dirs
- *   An associative array of extension directories, keyed by extension name.
- */
-function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $loader, $dirs) {
-  foreach ($dirs as $extension => $dir) {
-    if (is_dir($dir . '/src')) {
-      // Register the PSR-4 directory for module-provided classes.
-      $loader->addPsr4('Drupal\\' . $extension . '\\', $dir . '/src');
-    }
-    if (is_dir($dir . '/tests/src')) {
-      // Register the PSR-4 directory for PHPUnit test classes.
-      $loader->addPsr4('Drupal\\' . $extension . '\Tests\\', $dir . '/tests/src');
-    }
-  }
-}
-
-// Start with classes in known locations.
 $loader = require __DIR__ . '/../vendor/autoload.php';
-$loader->add('Drupal\\Tests', __DIR__);
 
-// Scan for arbitrary extension namespaces from core and contrib.
-$extension_roots = array_merge(array(
-  __DIR__ . '/../modules',
-  __DIR__ . '/../profiles',
-), drupal_phpunit_contrib_extension_directory_roots());
+// @todo Remove the following constants.
+define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
+define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
 
-$dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
-$dirs = array_reduce($dirs, 'array_merge', array());
-drupal_phpunit_register_extension_dirs($loader, $dirs);
+// As long as no further classes are needed, a single include is sufficient.
+require_once __DIR__ . '/../modules/simpletest/src/TestDiscovery.php';
 
-// Look into removing these later.
-define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
-define('DRUPAL_ROOT', realpath(__DIR__ . '/../../'));
+$discovery = new TestDiscovery($loader);
+$discovery->registerTestNamespaces();
 
 // Set sane locale settings, to ensure consistent string, dates, times and
 // numbers handling.
