Skip to content

Commit 09c4b1f

Browse files
committed
Add deprecation warning.
1 parent 1000e33 commit 09c4b1f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Twig/TwigSortTokenParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class TwigSortTokenParser extends AbstractTokenParser {
1919
* {@inheritdoc}
2020
*/
2121
public function parse(Token $token): Node {
22+
\trigger_error('The sort tag is deprecated in 3.6.0 and will be removed in 4.x, use the sort_namespaces twig filter.', \E_USER_WARNING);
2223
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
2324
$body = $this->parser->subparse(
2425
static fn (Token $token): bool => $token->test('endsort'),

tests/unit/TwigEnvironmentTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DrupalCodeGenerator\Twig\TwigEnvironment;
88
use PHPUnit\Framework\TestCase;
9+
use Twig\Error\SyntaxError;
910
use Twig\Loader\FilesystemLoader;
1011

1112
/**
@@ -20,8 +21,20 @@ public function testTwigEnvironment(): void {
2021
$twig_loader = new FilesystemLoader(__DIR__);
2122
$twig = new TwigEnvironment($twig_loader);
2223
$expected = \file_get_contents(__DIR__ . '/_twig_environment_fixture.txt');
23-
$result = $twig->render('twig-environment-template.twig', []);
24+
\error_reporting(\error_reporting() & ~ \E_USER_WARNING);
25+
$result = $twig->render('twig-environment-template.twig');
2426
self::assertSame($expected, $result);
2527
}
2628

29+
/**
30+
* Test callback.
31+
*/
32+
public function testDeprecateTagTwigEnvironment(): void {
33+
$twig_loader = new FilesystemLoader(__DIR__);
34+
$twig = new TwigEnvironment($twig_loader);
35+
$this->expectException(SyntaxError::class);
36+
$this->expectExceptionMessage('An exception has been thrown during the compilation of a template ("The sort tag is deprecated in 3.6.0 and will be removed in 4.x, use the sort_namespaces twig filter.") in "twig-environment-template.twig".');
37+
$twig->render('twig-environment-template.twig');
38+
}
39+
2740
}

0 commit comments

Comments
 (0)