diff --git a/core/includes/module.inc b/core/includes/module.inc
index c1d99f2..70db601 100644
--- a/core/includes/module.inc
+++ b/core/includes/module.inc
@@ -182,7 +182,7 @@ function system_list($type) {
       // Drupal installations, which might have modules installed in different
       // locations in the file system. The ordering here must also be
       // consistent with the one used in module_implements().
-      $enabled_modules = config('system.module')->get('enabled');
+      $enabled_modules = (array) config('system.module')->get('enabled');
       $module_files = state()->get('system.module.files');
       foreach ($enabled_modules as $name => $weight) {
         // Build a list of all enabled modules.
@@ -196,7 +196,7 @@ function system_list($type) {
       }
 
       // Build a list of themes.
-      $enabled_themes = config('system.theme')->get('enabled');
+      $enabled_themes = (array) config('system.theme')->get('enabled');
       // @todo Themes include all themes, including disabled/uninstalled. This
       //   system.theme.data state will go away entirely as soon as themes have
       //   a proper installation status.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index b31d8a0..c0f156e 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -811,11 +811,6 @@ protected function prepareEnvironment() {
     unset($GLOBALS['theme_key']);
     unset($GLOBALS['theme']);
 
-    // Re-initialize the theme to ensure that tests do not see an inconsistent
-    // behavior when calling functions that would initialize the theme if it has
-    // not been initialized yet.
-    drupal_theme_initialize();
-
     // Log fatal errors.
     ini_set('log_errors', 1);
     ini_set('error_log', $this->public_files_directory . '/error.log');
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
index 98ed71d..79f7f77 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
@@ -66,6 +66,11 @@ protected function setUp() {
       return FALSE;
     }
 
+    // Re-initialize the theme to ensure that tests do not see an inconsistent
+    // behavior when calling functions that would initialize the theme if it has
+    // not been initialized yet.
+    drupal_theme_initialize();
+
     // Set user agent to be consistent with WebTestBase.
     $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix;
 
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 8ad58ef..7071e31 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -722,6 +722,11 @@ protected function setUp() {
       $this->rebuildContainer();
     }
 
+    // Re-initialize the theme to ensure that tests do not see an inconsistent
+    // behavior when calling functions that would initialize the theme if it has
+    // not been initialized yet.
+    drupal_theme_initialize();
+
     // Reset/rebuild all data structures after enabling the modules.
     $this->resetAll();
 
