diff --git a/core/modules/system/src/Tests/Common/ExtensionDiscoveryProfilesTest.php b/core/modules/system/src/Tests/Common/ExtensionDiscoveryProfilesTest.php
deleted file mode 100644
index 4ae1713..0000000
--- a/core/modules/system/src/Tests/Common/ExtensionDiscoveryProfilesTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\system\Tests\Common\ExtensionDiscoveryProfilesTest.
- */
-
-namespace Drupal\system\Tests\Common;
-
-use Drupal\Core\Extension\ExtensionDiscovery;
-use Drupal\Core\Site\Settings;
-use Drupal\simpletest\KernelTestBase;
-
-/**
- * Tests setting profileDirectories from settings.
- *
- * @group Common
- */
-class ExtensionDiscoveryProfilesTest extends KernelTestBase {
-  /**
-   * Tests that files in different directories take precedence as expected.
-   */
-  function testDirectoryPrecedence() {
-    // Define the module files we will search for, and the directory precedence
-    // we expect.
-    $expected_directories = array(
-      // When both copies of the module are compatible with Drupal core, the
-      // copy in the profile directory takes precedence.
-      'drupal_system_listing_compatible_test' => array(
-        'core/profiles/testing/modules',
-        'core/modules/system/tests/modules',
-      ),
-    );
-
-    // This test relies on two versions of the same module existing in
-    // different places in the filesystem. Without that, the test has no
-    // meaning, so assert their presence first.
-    foreach ($expected_directories as $module => $directories) {
-      foreach ($directories as $directory) {
-        $filename = "$directory/$module/$module.info.yml";
-        $this->assertTrue(file_exists(\Drupal::root() . '/' . $filename), format_string('@filename exists.', array('@filename' => $filename)));
-      }
-    }
-
-    // Now add the testing profile path to settings.
-    $settings = Settings::getAll();
-    $settings['profile_directories'] = array (
-      0 => 'core/profiles/testing',
-    );
-    new Settings($settings);
-
-    // Now scan the directories and check that the files take precedence as
-    // expected.
-    $listing = new ExtensionDiscovery(\Drupal::root());
-    $files = $listing->scan('module');
-    foreach ($expected_directories as $module => $directories) {
-      $expected_directory = array_shift($directories);
-      $expected_uri = "$expected_directory/$module/$module.info.yml";
-      $this->assertEqual($files[$module]->getPathname(), $expected_uri, format_string('Module @actual was found at @expected.', array(
-        '@actual' => $files[$module]->getPathname(),
-        '@expected' => $expected_uri,
-      )));
-    }
-  }
-}
diff --git a/core/modules/system/tests/src/Kernel/System/ExtensionDiscoveryProfilesTest.php b/core/modules/system/tests/src/Kernel/System/ExtensionDiscoveryProfilesTest.php
new file mode 100644
index 0000000..e2df9a4
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/System/ExtensionDiscoveryProfilesTest.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\System;
+
+use Drupal\Core\Extension\ExtensionDiscovery;
+use Drupal\Core\Site\Settings;
+use Drupal\KernelTests\KernelTestBase;
+use org\bovigo\vfs\vfsStream;
+use Symfony\Component\Yaml\Yaml;
+
+/**
+ * Tests setting profileDirectories from settings.
+ *
+ * @group Extension
+ */
+class ExtensionDiscoveryProfilesTest extends KernelTestBase {
+  /**
+   * Tests that files in different directories take precedence as expected.
+   */
+  function testDirectoryPrecedence() {
+    // Set up the file system.
+    $filesystem = [];
+    $files_by_type_and_name_expected = $this->populateFilesystemStructure($filesystem);
+
+    $vfs = vfsStream::setup('root', NULL, $filesystem);
+    $root = $vfs->url();
+
+    // Define the module files we will search for, and the directory precedence
+    // we expect.
+    $expected_directories = array(
+      // When both copies of the module are compatible with Drupal core, the
+      // copy in the profile directory takes precedence.
+      'drupal_system_listing_compatible_test' => array(
+        'core/profiles/testing/modules',
+        'core/modules/system/tests/modules',
+      ),
+    );
+
+    // This test relies on two versions of the same module existing in
+    // different places in the filesystem. Without that, the test has no
+    // meaning, so assert their presence first.
+    foreach ($expected_directories as $module => $directories) {
+      foreach ($directories as $directory) {
+        $filename = "$directory/$module/$module.info.yml";
+        $this->assertFileExists($root . $filename);
+      }
+    }
+
+    // Now add the testing profile path to settings.
+    $settings = Settings::getAll();
+    $settings['profile_directories'] = array (
+      0 => 'core/profiles/testing',
+    );
+    new Settings($settings);
+
+    // Now scan the directories and check that the files take precedence as
+    // expected.
+    $listing = new ExtensionDiscovery($root);
+    $files = $listing->scan('module');
+    foreach ($expected_directories as $module => $directories) {
+      $expected_directory = array_shift($directories);
+      $expected_uri = "$expected_directory/$module/$module.info.yml";
+      $this->assertEqual($files[$module]->getPathname(), $expected_uri, format_string('Module @actual was found at @expected.', array(
+        '@actual' => $files[$module]->getPathname(),
+        '@expected' => $expected_uri,
+      )));
+      $this->assertFileNotExists($files[$module]->getPathname());
+    }
+  }
+
+  /**
+   * Adds example files to the filesystem structure.
+   *
+   * @param array $filesystem_structure
+   *
+   * @return string[][]
+   *   Format: $[$type][$name] = $yml_file
+   *   E.g. $['module']['system'] = 'system.info.yml'
+   */
+  protected function populateFilesystemStructure(array &$filesystem_structure) {
+    $info_by_file = [
+      'core/profiles/testing/testing.info.yml' => [
+        'type' => 'profile',
+      ],
+      'core/profiles/testing/modules/abc/abc.info.yml' => [
+        'type' => 'module',
+      ],
+      // Add another instance of abc module.
+      'core/modules/system/tests/modules/abc/abc.info.yml' => [
+        'type' => 'module',
+      ],
+    ];
+
+    $files_by_type_and_name_expected = [];
+    $content_by_file = [];
+    foreach ($info_by_file as $file => $info) {
+      $name = basename($file, '.info.yml');
+      $info += [
+        'type' => 'module',
+        'name' => "Name of ($name)",
+        'core' => '8.x',
+      ];
+      $type = $info['type'];
+      $content_by_file[$file] = Yaml::dump($info);
+      $files_by_type_and_name_expected[$type][$name] = $file;
+    }
+
+    $content_by_file['core/modules/system/system.module'] = '<?php';
+    $content_by_file['core/themes/engines/twig/twig.engine'] = '<?php';
+
+    foreach ($content_by_file as $file => $content) {
+      $pieces = explode('/', $file);
+      $this->addFileToFilesystemStructure($filesystem_structure, $pieces, $content);
+    }
+
+    unset($files_by_type_and_name_expected['module']['otherprofile_nested_module']);
+
+    return $files_by_type_and_name_expected;
+  }
+
+  /**
+   * @param array $filesystem_structure
+   * @param string[] $pieces
+   *   Fragments of the file path.
+   * @param string $content
+   */
+  protected function addFileToFilesystemStructure(array &$filesystem_structure, array $pieces, $content) {
+    $piece = array_shift($pieces);
+    if ($pieces !== []) {
+      $filesystem_structure += [$piece => []];
+      $this->addFileToFilesystemStructure($filesystem_structure[$piece], $pieces, $content);
+    }
+    else {
+      $filesystem_structure[$piece] = $content;
+    }
+  }
+
+}
