Skip to content

Commit

Permalink
Merge pull request #1144 from VincentLanglet/emptyArray
Browse files Browse the repository at this point in the history
Improve replaceQueryParameters function for empty array
  • Loading branch information
greg0ire committed Mar 14, 2020
2 parents ac31f33 + e442467 commit efc5ed4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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 @@ -98,7 +98,7 @@ public static function escapeFunction($parameter)
$value = static::escapeFunction($value);
}

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

case is_object($result):
Expand Down

0 comments on commit efc5ed4

Please sign in to comment.