diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index 707968b..780a6bd 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -57,7 +57,12 @@ function drupal_error_levels() {
  *   occurred.
  */
 function _drupal_error_handler_real($error_level, $message, $filename, $line, $context) {
-  if ($error_level & error_reporting()) {
+  // Only PHP 5.x uses E_RECOVERABLE_ERROR - PHP 7 throws TypeExceptions.
+  // Throw an exception here to make the behavior consistent.
+  if ($error_level & E_RECOVERABLE_ERROR) {
+    throw new TypeException($message);
+  }
+  elseif ($error_level & error_reporting()) {
     $types = drupal_error_levels();
     list($severity_msg, $severity_level) = $types[$error_level];
     $backtrace = debug_backtrace();
diff --git a/core/includes/php7shim.inc b/core/includes/php7shim.inc
new file mode 100644
index 0000000..1967668
--- /dev/null
+++ b/core/includes/php7shim.inc
@@ -0,0 +1,28 @@
+<?php
+/**
+ * @file
+ * Force PHP 5.x to behave as PHP 7 does as much as possible.
+ *
+ * PHP 7 can throw exceptions in many situations where PHP 5.x uses errors.
+ * This can make writing tests that pass both versions something of a headache.
+ * The situation can be eased some by using the callbacks provided by the PHP
+ * engine.
+ */
+
+if (version_compare(PHP_VERSION, '7.0.0-dev') === -1) {
+  /**
+   * Assertions should throw Exceptions.
+   */
+  class AssertionException extends Exception {}
+
+  assert_options(ASSERT_CALLBACK, function($file, $line, $code, $message = '') {
+    if (empty($message)) {
+      $message = "Assertion Failure in {$file} at {$line}. Failed asserting {$code}";
+    }
+    throw new AssertionException($message);
+  });
+
+  set_error_handler(function($number, $message, $file, $line, $context){
+    throw new TypeException($message);
+  }, E_RECOVERABLE_ERROR);
+}
diff --git a/core/tests/Drupal/Tests/PHPShimTest.php b/core/tests/Drupal/Tests/PHPShimTest.php
new file mode 100644
index 0000000..d2c600e
--- /dev/null
+++ b/core/tests/Drupal/Tests/PHPShimTest.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\PHPShimTest.
+ */
+
+namespace Drupal\Tests;
+
+/**
+ * Tests the PHP 5.x to 7 shim.
+ *
+ * @see core/includes/php7shim.inc
+ *
+ * @ingroup testing
+ *
+ * @group PHPShimTest
+ */
+class PHPShimTest extends \PHPUnit_Framework_TestCase {
+
+  /**
+   * Tests if assert() fails always result in an AssertionException throw.
+   *
+   * @expectedException AssertionException
+   */
+  public function testAssertRuntimeFailure() {
+    assert(false);
+  }
+}
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index fd980a4..74527e6 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -67,6 +67,9 @@ function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $l
   }
 }
 
+// Load PHP 5.x to 7 shim.
+require_once __DIR__ . '/../includes/php7shim.inc';
+
 // Start with classes in known locations.
 $loader = require __DIR__ . '/../../autoload.php';
 $loader->add('Drupal\\Tests', __DIR__);
diff --git a/index.php b/index.php
index 750dc28..e0ae884 100644
--- a/index.php
+++ b/index.php
@@ -11,6 +11,7 @@
 use Drupal\Core\DrupalKernel;
 use Symfony\Component\HttpFoundation\Request;
 
+require_once 'core/includes/php7shim.inc';
 $autoloader = require_once 'autoload.php';
 
 $kernel = new DrupalKernel('prod', $autoloader);
