Skip to content

Commit

Permalink
Add deprecation warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
chesn0k committed May 17, 2024
1 parent 1000e33 commit 09c4b1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Twig/TwigSortTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class TwigSortTokenParser extends AbstractTokenParser {
* {@inheritdoc}
*/
public function parse(Token $token): Node {
\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);
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(
static fn (Token $token): bool => $token->test('endsort'),
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/TwigEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DrupalCodeGenerator\Twig\TwigEnvironment;
use PHPUnit\Framework\TestCase;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;

/**
Expand All @@ -20,8 +21,20 @@ public function testTwigEnvironment(): void {
$twig_loader = new FilesystemLoader(__DIR__);
$twig = new TwigEnvironment($twig_loader);
$expected = \file_get_contents(__DIR__ . '/_twig_environment_fixture.txt');
$result = $twig->render('twig-environment-template.twig', []);
\error_reporting(\error_reporting() & ~ \E_USER_WARNING);
$result = $twig->render('twig-environment-template.twig');
self::assertSame($expected, $result);
}

/**
* Test callback.
*/
public function testDeprecateTagTwigEnvironment(): void {
$twig_loader = new FilesystemLoader(__DIR__);
$twig = new TwigEnvironment($twig_loader);
$this->expectException(SyntaxError::class);
$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".');
$twig->render('twig-environment-template.twig');
}

}

0 comments on commit 09c4b1f

Please sign in to comment.