Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve replaceQueryParameters function for empty array #1144

Merged
merged 1 commit into from Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion Tests/Twig/DoctrineExtensionTest.php
Expand Up @@ -56,6 +56,18 @@ public function testReplaceQueryParametersWithNamedIndex() : void
$this->assertEquals('a=1 OR b=2', $result);
}

public function testReplaceQueryParametersWithEmptyArray() : void
{
$extension = new DoctrineExtension();
$query = 'IN (?)';
$parameters = [
[],
];

$result = $extension->replaceQueryParameters($query, $parameters);
$this->assertEquals('IN (NULL)', $result);
}

public function testEscapeBinaryParameter() : void
{
$binaryString = pack('H*', '9d40b8c1417f42d099af4782ec4b20b6');
Expand All @@ -69,7 +81,7 @@ public function testEscapeStringParameter() : void

public function testEscapeArrayParameter() : void
{
$this->assertEquals("1, NULL, 'test', foo", DoctrineExtension::escapeFunction([1, null, 'test', new DummyClass('foo')]));
$this->assertEquals("1, NULL, 'test', foo, NULL", DoctrineExtension::escapeFunction([1, null, 'test', new DummyClass('foo'), []]));
}

public function testEscapeObjectParameter() : void
Expand Down
2 changes: 1 addition & 1 deletion Twig/DoctrineExtension.php
Expand Up @@ -96,7 +96,7 @@ public static function escapeFunction($parameter)
$value = static::escapeFunction($value);
}

$result = implode(', ', $result);
$result = implode(', ', $result) ?: 'NULL';
break;

case is_object($result):
Expand Down