diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php
index 9225712..1f13890 100644
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php
+++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php
@@ -40,6 +40,7 @@ class TwigEnvironment extends \Twig_Environment {
    *   The options for the Twig environment.
    */
   public function __construct($root, \Twig_LoaderInterface $loader = NULL, $options = array()) {
+    assert('is_string($root)', 'Parameter must be a string');
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
 
@@ -137,8 +138,9 @@ public function loadTemplate($name, $index = NULL) {
     if (!$this->runtimeInitialized) {
         $this->initRuntime();
     }
-
-    return $this->loadedTemplates[$cls] = new $cls($this);
+    $this->loadedTemplates[$cls] = new $cls($this);
+    assert('$this->loadedTemplates[$cls] instanceof \Twig_TemplateInterface', 'invalidReturn');
+    return $this->loadedTemplates[$cls];
   }
 
   /**
@@ -150,6 +152,7 @@ protected function storage() {
     if (!isset($this->storage)) {
       $this->storage = PhpStorageFactory::get('twig');
     }
+    assert('$this->storage instanceof \Drupal\Component\PhpStorage\PhpStorageInterface', 'invalidReturn');
     return $this->storage;
   }
 
@@ -173,6 +176,7 @@ public function getTemplateClass($name, $index = NULL) {
     if (!isset($this->templateClasses[$cache_index])) {
       $this->templateClasses[$cache_index] = $this->templateClassPrefix . hash('sha256', $this->loader->getCacheKey($name)) . (NULL === $index ? '' : '_' . $index);
     }
+    assert('is_string($this->templateClasses[$cache_index])', 'invalidReturn');
     return $this->templateClasses[$cache_index];
   }
 
@@ -201,7 +205,9 @@ public function getTemplateClass($name, $index = NULL) {
   public function renderInline($template_string, array $context = array()) {
     // Prefix all inline templates with a special comment.
     $template_string = '{# inline_template_start #}' . $template_string;
-    return $this->loadTemplate($template_string, NULL)->render($context);
+    $return = $this->loadTemplate($template_string, NULL)->render($context);
+    assert('is_string($return)', 'invalidReturn');
+    return $return;
   }
 
 }
diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index bb29cd1..dc908d8 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -17,6 +17,9 @@
 use Drupal\Core\Routing\UrlGeneratorInterface;
 use Drupal\Core\Url;
 use Drupal\Core\Utility\LinkGeneratorInterface;
+use Twig_SimpleFunction;
+use Twig_SimpleFilter;
+use Twig_Node;
 
 /**
  * A class providing Drupal Twig extensions.
@@ -90,15 +93,15 @@ public function setLinkGenerator(LinkGeneratorInterface $link_generator) {
   public function getFunctions() {
     return array(
       // This function will receive a renderable array, if an array is detected.
-      new \Twig_SimpleFunction('render_var', array($this, 'renderVar')),
+      new Twig_SimpleFunction('render_var', array($this, 'renderVar')),
       // The url and path function are defined in close parallel to those found
       // in \Symfony\Bridge\Twig\Extension\RoutingExtension
-      new \Twig_SimpleFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
-      new \Twig_SimpleFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
-      new \Twig_SimpleFunction('url_from_path', array($this, 'getUrlFromPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
-      new \Twig_SimpleFunction('link', array($this, 'getLink')),
-      new \Twig_SimpleFunction('file_url', 'file_create_url'),
-      new \Twig_SimpleFunction('attach_library', array($this, 'attachLibrary'))
+      new Twig_SimpleFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
+      new Twig_SimpleFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
+      new Twig_SimpleFunction('url_from_path', array($this, 'getUrlFromPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
+      new Twig_SimpleFunction('link', array($this, 'getLink')),
+      new Twig_SimpleFunction('file_url', 'file_create_url'),
+      new Twig_SimpleFunction('attach_library', array($this, 'attachLibrary'))
     );
   }
 
@@ -108,32 +111,32 @@ public function getFunctions() {
   public function getFilters() {
     return array(
       // Translation filters.
-      new \Twig_SimpleFilter('t', 't', array('is_safe' => array('html'))),
-      new \Twig_SimpleFilter('trans', 't', array('is_safe' => array('html'))),
+      new Twig_SimpleFilter('t', 't', array('is_safe' => array('html'))),
+      new Twig_SimpleFilter('trans', 't', array('is_safe' => array('html'))),
       // The "raw" filter is not detectable when parsing "trans" tags. To detect
       // which prefix must be used for translation (@, !, %), we must clone the
       // "raw" filter and give it identifiable names. These filters should only
       // be used in "trans" tags.
       // @see TwigNodeTrans::compileString()
-      new \Twig_SimpleFilter('passthrough', 'twig_raw_filter', array('is_safe' => array('html'))),
-      new \Twig_SimpleFilter('placeholder', 'twig_raw_filter', array('is_safe' => array('html'))),
+      new Twig_SimpleFilter('passthrough', 'twig_raw_filter', array('is_safe' => array('html'))),
+      new Twig_SimpleFilter('placeholder', 'twig_raw_filter', array('is_safe' => array('html'))),
 
       // Replace twig's escape filter with our own.
-      new \Twig_SimpleFilter('drupal_escape', [$this, 'escapeFilter'], array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')),
+      new Twig_SimpleFilter('drupal_escape', [$this, 'escapeFilter'], array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')),
 
       // Implements safe joining.
       // @todo Make that the default for |join? Upstream issue:
       //   https://github.com/fabpot/Twig/issues/1420
-      new \Twig_SimpleFilter('safe_join', 'twig_drupal_join_filter', array('is_safe' => array('html'))),
+      new Twig_SimpleFilter('safe_join', 'twig_drupal_join_filter', array('is_safe' => array('html'))),
 
       // Array filters.
-      new \Twig_SimpleFilter('without', 'twig_without'),
+      new Twig_SimpleFilter('without', 'twig_without'),
 
       // CSS class and ID filters.
-      new \Twig_SimpleFilter('clean_class', '\Drupal\Component\Utility\Html::getClass'),
-      new \Twig_SimpleFilter('clean_id', '\Drupal\Component\Utility\Html::getId'),
+      new Twig_SimpleFilter('clean_class', '\Drupal\Component\Utility\Html::getClass'),
+      new Twig_SimpleFilter('clean_id', '\Drupal\Component\Utility\Html::getId'),
       // This filter will render a renderable array to use the string results.
-      new \Twig_SimpleFilter('render', array($this, 'renderVar')),
+      new Twig_SimpleFilter('render', array($this, 'renderVar')),
     );
   }
 
@@ -180,6 +183,7 @@ public function getName() {
    *   The generated URL path (relative URL) for the given route.
    */
   public function getPath($name, $parameters = array(), $options = array()) {
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'missingGenerators');
     $options['absolute'] = FALSE;
     return $this->urlGenerator->generateFromRoute($name, $parameters, $options);
   }
@@ -201,6 +205,7 @@ public function getPath($name, $parameters = array(), $options = array()) {
    * @todo Add an option for scheme-relative URLs.
    */
   public function getUrl($name, $parameters = array(), $options = array()) {
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'missingGenerators');
     $options['absolute'] = TRUE;
     return $this->urlGenerator->generateFromRoute($name, $parameters, $options);
   }
@@ -220,6 +225,7 @@ public function getUrl($name, $parameters = array(), $options = array()) {
    * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 8.0.0.
    */
   public function getUrlFromPath($path, $options = array()) {
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'missingGenerators');
     $options['absolute'] = TRUE;
     return $this->urlGenerator->generateFromPath($path, $options);
   }
@@ -236,6 +242,7 @@ public function getUrlFromPath($path, $options = array()) {
    *   An HTML string containing a link to the given url.
    */
   public function getLink($text, $url) {
+    assert('$this->linkGenerator instanceof \\Drupal\\Core\\Utility\\LinkGeneratorInterface', 'missingGenerators');
     if (!$url instanceof Url) {
       $url = Url::fromUri($url);
     }
@@ -269,7 +276,7 @@ public function getLink($text, $url) {
    * @return array
    *   An array with the contexts the URL is safe
    */
-  public function isUrlGenerationSafe(\Twig_Node $args_node) {
+  public function isUrlGenerationSafe(Twig_Node $args_node) {
     // Support named arguments.
     $parameter_node = $args_node->hasNode('parameters') ? $args_node->getNode('parameters') : ($args_node->hasNode(1) ? $args_node->getNode(1) : NULL);
 
diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
index 3866965..d20b23a 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @file
  * Contains \Drupal\Tests\Core\Template\TwigExtensionTest.
@@ -9,6 +8,7 @@
 
 use Drupal\Core\Template\TwigExtension;
 use Drupal\Tests\UnitTestCase;
+use Drupal\Tests\AssertionTestingTrait;
 
 /**
  * Tests the twig extension.
@@ -19,30 +19,65 @@
  */
 class TwigExtensionTest extends UnitTestCase {
 
+  use AssertionTestingTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    $this->startAssertionHandling();
+    $this->verifyMessage = TRUE;
+    parent::setUp();
+  }
+
   /**
-   * Tests the escaping
+   * Tests the escaping.
    *
    * @dataProvider providerTestEscaping
    */
   public function testEscaping($template, $expected) {
-    $renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
+    $renderer = $this->getMock('\\Drupal\\Core\\Render\\RendererInterface');
     $twig = new \Twig_Environment(NULL, array(
       'debug' => TRUE,
       'cache' => FALSE,
       'autoescape' => TRUE,
       'optimizations' => 0
     ));
-    $twig->addExtension((new TwigExtension($renderer))->setGenerators($this->getMock('Drupal\Core\Routing\UrlGeneratorInterface')));
+    $twig->addExtension((new TwigExtension($renderer))->setGenerators($this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface')));
 
     $nodes = $twig->parse($twig->tokenize($template));
 
     $this->assertSame($expected, $nodes->getNode('body')
         ->getNode(0)
         ->getNode('expr') instanceof \Twig_Node_Expression_Filter);
+
+    $this->assertAssertionNotRaised();
+  }
+
+  /**
+   * Test Assertions.
+   *
+   * If a module is misconfigured the path generators can be missing.
+   */
+  public function testAssertions() {
+    $twigExt = new TwigExtensionWrapper($this->getMock('\\Drupal\\Core\\Render\\RendererInterface'));
+    $twigExt->unprotectedSetGenerator(new FalseUrlGenerator());
+    $twigExt->unprotectedSetLinkGenerator(new FalseLinkGenerator());
+    $this->assertAssertionNotRaised();
+
+    $twigExt->getPath('blah');
+    $this->assertAssertionsRaised('missingGenerators');
+
+    $twigExt->getUrl('blah');
+    $this->assertAssertionsRaised('missingGenerators');
+
+    $twigExt->getUrlFromPath('blah');
+    $this->assertAssertionsRaised('missingGenerators');
+
   }
 
   /**
-   * Provides tests data for testEscaping
+   * Provides tests data for testEscaping.
    *
    * @return array
    *   An array of test data each containing of a twig template string and
@@ -62,14 +97,66 @@ public function providerTestEscaping() {
       array('{{ path(name = "foo", parameters = foo) }}', TRUE),
       array(
         '{{ path(name = "foo", parameters = { foo: ["foo", "bar"] }) }}',
-        TRUE
+        TRUE,
       ),
       array('{{ path(name = "foo", parameters = { foo: foo }) }}', TRUE),
       array(
         '{{ path(name = "foo", parameters = { foo: "foo", bar: "bar" }) }}',
-        TRUE
+        TRUE,
       ),
     );
   }
 
 }
+
+
+/**
+ * This wrapper allows phony Link and URL generators for assert tests.
+ */
+class TwigExtensionWrapper extends TwigExtension {
+  /**
+   * Foo.
+   */
+  public function unprotectedSetGenerator($url_generator) {
+    $this->urlGenerator = $url_generator;
+  }
+  /**
+   * Boo.
+   */
+  public function unprotectedSetLinkGenerator($link_generator) {
+    $this->linkGenerator = $link_generator;
+  }
+
+}
+
+/**
+ * False Link Generator for assert fail test.
+ */
+class FalseLinkGenerator {
+  /**
+   * Fake.
+   */
+  public function generate($text, $url) {
+    return 'foo';
+  }
+
+}
+
+/**
+ * False URL Generator for assert fail test.
+ */
+class FalseURLGenerator {
+  /**
+   * Fake.
+   */
+  public function generateFromRoute($name, $parameters, $options) {
+    return 'foo';
+  }
+  /**
+   * Also fake.
+   */
+  public function generateFromPath($path, $options) {
+    return 'foo';
+  }
+
+}
