diff --git a/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerEmptySettingsTest.php b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerEmptySettingsTest.php
new file mode 100644
index 0000000..6f3302e
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerEmptySettingsTest.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Installer\InstallerEmptySettingsTest.
+ */
+
+namespace Drupal\system\Tests\Installer;
+
+use Drupal\simpletest\InstallerTestBase;
+
+/**
+ * Tests the installer with empty settings file.
+ */
+class InstallerEmptySettingsTest extends InstallerTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Installer Empty Settings Test',
+      'description' => 'Tests the installer with empty settings file.',
+      'group' => 'Installer',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    // Create an empty settings.php file.
+    touch($this->siteDirectory . '/settings.php');
+    parent::setUp();
+  }
+
+  /**
+   * Verifies that installation succeeded.
+   */
+  public function testInstaller() {
+    $this->assertUrl('user/1');
+    $this->assertResponse(200);
+  }
+
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php b/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php
index 74c080d..40c394c 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php
@@ -109,5 +109,26 @@ function testDrupalRewriteSettings() {
       drupal_rewrite_settings($test['settings'], $filename);
       $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
     }
+
+    // Test that <?php gets added to the start of an empty settings file.
+    // Set the array of settings that will be written to the file.
+    $test = array(
+      'settings' => array(
+        'no_index' => (object) array(
+          'value' => TRUE,
+          'required' => TRUE,
+        ),
+      ),
+      'expected' => '$no_index = true;'
+    );
+    // Make an empty file.
+    $filename = settings()->get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
+    file_put_contents(DRUPAL_ROOT . '/' . $filename, "");
+
+    // Write the setting to the file.
+    drupal_rewrite_settings($test['settings'], $filename);
+
+    // Check that the result is just the php opening tag and the settings.
+    $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
   }
 }
