Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
* 3.x:
  Move some tests
  • Loading branch information
fabpot committed Feb 26, 2025
2 parents 50cdb7b + b6e7097 commit 4a3f02f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 65 deletions.
39 changes: 39 additions & 0 deletions tests/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Twig\Compiler;
use Twig\Environment;
use Twig\Error\Error;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\ArrayLoader;
Expand Down Expand Up @@ -414,6 +415,44 @@ public static function getErroredTemplates()
],
];
}

public function testErrorFromArrayLoader()
{
$templates = [
'index.twig' => '{% include "include.twig" %}',
'include.twig' => $include = <<<EOF
{% extends 'invalid.twig' %}
EOF,
];
$twig = new Environment(new ArrayLoader($templates), ['debug' => true, 'cache' => false]);
try {
$twig->render('index.twig');
$this->fail('Expected LoaderError to be thrown');
} catch (LoaderError $e) {
$this->assertSame('Template "invalid.twig" is not defined.', $e->getRawMessage());
$this->assertSame(4, $e->getTemplateLine());
$this->assertSame('include.twig', $e->getSourceContext()->getName());
$this->assertSame($include, $e->getSourceContext()->getCode());
}
}

public function testErrorFromFilesystemLoader()
{
$twig = new Environment(new FilesystemLoader([$dir = __DIR__.'/Fixtures/errors/extends']), ['debug' => true, 'cache' => false]);
$include = file_get_contents($dir.'/include.twig');
try {
$twig->render('index.twig');
$this->fail('Expected LoaderError to be thrown');
} catch (LoaderError $e) {
$this->assertStringContainsString('Unable to find template "invalid.twig"', $e->getRawMessage());
$this->assertSame(4, $e->getTemplateLine());
$this->assertSame('include.twig', $e->getSourceContext()->getName());
$this->assertSame($include, $e->getSourceContext()->getCode());
}
}
}

class ErrorTest_Foo
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/errors/extends/include.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@



{% extends 'invalid.twig' %}
1 change: 1 addition & 0 deletions tests/Fixtures/errors/extends/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "include.twig" %}
65 changes: 0 additions & 65 deletions tests/Node/ExtendsTest.php

This file was deleted.

0 comments on commit 4a3f02f

Please sign in to comment.