mirror of
https://github.com/twigphp/Twig.git
synced 2026-11-03 17:45:15 +00:00
Fix an empty destructuring pattern triggering a PHP fatal error instead of a SyntaxError
This commit is contained in:
@@ -268,6 +268,25 @@ class ExpressionParserTest extends TestCase
|
||||
$this->assertSame('third', $pairs[2]['value']->getAttribute('name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getEmptyDestructuringTests
|
||||
*/
|
||||
#[DataProvider('getEmptyDestructuringTests')]
|
||||
public function testEmptyDestructuringThrows(string $template): void
|
||||
{
|
||||
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
|
||||
|
||||
$this->expectException(SyntaxError::class);
|
||||
$this->expectExceptionMessage('Cannot destructure to an empty list of variables');
|
||||
$env->compileSource(new Source($template, 'index'));
|
||||
}
|
||||
|
||||
public static function getEmptyDestructuringTests()
|
||||
{
|
||||
yield ['{% do [] = values %}'];
|
||||
yield ['{% do {} = values %}'];
|
||||
}
|
||||
|
||||
public function testObjectDestructuringUsesAssignmentTargets(): void
|
||||
{
|
||||
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
|
||||
|
||||
Reference in New Issue
Block a user