17 $error->setSourceContext(
new Twig_Source(
'',
new SplFileInfo(__FILE__)));
19 $this->assertContains(
'test'.DIRECTORY_SEPARATOR.
'Twig'.DIRECTORY_SEPARATOR.
'Tests'.DIRECTORY_SEPARATOR.
'ErrorTest.php', $error->getMessage());
25 $error->setSourceContext(
new Twig_Source(
'', array(
'foo' =>
'bar')));
27 $this->assertEquals(
'foo in {"foo":"bar"}', $error->getMessage());
33 'base.html' =>
'{% block content %}{% endblock %}',
34 'index.html' => <<<EOHTML
35{% extends
'base.html' %}
44 $twig =
new Twig_Environment($loader, array(
'strict_variables' =>
true,
'debug' =>
true,
'cache' =>
false));
46 $template = $twig->loadTemplate(
'index.html');
52 $this->assertEquals(
'Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage());
61 'base.html' =>
'{% block content %}{% endblock %}',
62 'index.html' => <<<EOHTML
63{% extends
'base.html' %}
72 $twig =
new Twig_Environment($loader, array(
'strict_variables' =>
true,
'debug' =>
true,
'cache' =>
false));
74 $template = $twig->loadTemplate(
'index.html');
80 $this->assertEquals(
'An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage());
89 $twig =
new Twig_Environment($loader, array(
'strict_variables' =>
true,
'debug' =>
true,
'cache' =>
false));
91 $template = $twig->loadTemplate(
'index.html');
97 $this->assertEquals(
'Variable "foo" does not exist.', $e->getMessage());
100 $this->assertEquals(3, $e->getLine());
101 $this->assertEquals(strtr(dirname(__FILE__).
'/Fixtures/errors/index.html',
'/', DIRECTORY_SEPARATOR), $e->getFile());
108 $twig =
new Twig_Environment($loader, array(
'strict_variables' =>
true,
'debug' =>
true,
'cache' =>
false));
110 $template = $twig->loadTemplate(
'index.html');
116 $this->assertEquals(
'An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
119 $this->assertEquals(3, $e->getLine());
120 $this->assertEquals(strtr(dirname(__FILE__).
'/Fixtures/errors/index.html',
'/', DIRECTORY_SEPARATOR), $e->getFile());
130 $twig =
new Twig_Environment($loader, array(
'strict_variables' =>
true,
'debug' =>
true,
'cache' =>
false));
132 $template = $twig->loadTemplate(
'index');
139 $this->assertEquals(sprintf(
'Variable "foo" does not exist in "%s" at line %d.',
$name, $line), $e->getMessage());
149 $this->assertEquals(sprintf(
'An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.',
$name, $line), $e->getMessage());
161 'index' =>
"\n\n{{ foo.bar }}\n\n\n{{ 'foo' }}",
169 'index' =>
"{% include 'partial' %}",
170 'partial' =>
'{{ foo.bar }}',
178 'index' =>
"{% extends 'base' %}
182 'base' =>
'{% block content %}{{ foo.bar }}{% endblock %}',
190 'index' =>
"{% extends 'base' %}
197 'base' =>
'{% block content %}{% endblock %}',
209 throw new Exception(
'Runtime error...');
An exception for terminatinating execution or to throw for unit testing.
Stores the Twig configuration.
Exception thrown when an error occurs at runtime.
getSourceContext()
Gets the source context of the Twig template where the error occurred.
getTemplateLine()
Gets the template line where the error occurred.
Loads a template from an array.
Loads template from the filesystem.
Holds information about a non-compiled Twig template.
testTwigExceptionGuessWithExceptionAndFilesystemLoader()
testTwigExceptionGuessWithMissingVarAndArrayLoader()
testTwigExceptionAddsFileAndLine($templates, $name, $line)
@dataProvider getErroredTemplates
testTwigExceptionGuessWithMissingVarAndFilesystemLoader()
testErrorWithArrayFilename()
testTwigExceptionGuessWithExceptionAndArrayLoader()
testErrorWithObjectFilename()