From ad1e7edf44ccdb35189e98271fb9ac38dd0d5711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Terje=20Br=C3=A5ten?= Date: Thu, 6 Nov 2014 14:41:05 +0000 Subject: [PATCH 1/2] Made the handling of NULL more consistent in the json_array type. --- lib/Doctrine/DBAL/Types/JsonArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Types/JsonArrayType.php b/lib/Doctrine/DBAL/Types/JsonArrayType.php index d54ab166c03..79c3259411b 100644 --- a/lib/Doctrine/DBAL/Types/JsonArrayType.php +++ b/lib/Doctrine/DBAL/Types/JsonArrayType.php @@ -54,7 +54,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null) { + if ($value === null || $value === '') { return array(); } From 4d99ed40110d5f6f7b174606fe5b2fe55d461973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Terje=20Br=C3=A5ten?= Date: Fri, 7 Nov 2014 15:21:06 +0000 Subject: [PATCH 2/2] Added a unit test for the type JsonArray, to test empty string conversion. --- tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 4d172a24242..0d1d29e7db0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -48,6 +48,11 @@ public function testJsonNullConvertsToPHPValue() $this->assertSame(array(), $this->type->convertToPHPValue(null, $this->platform)); } + public function testJsonEmptyStringConvertsToPHPValue() + { + $this->assertSame(array(), $this->type->convertToPHPValue('', $this->platform)); + } + public function testJsonStringConvertsToPHPValue() { $value = array('foo' => 'bar', 'bar' => 'foo');