From abcfa5c25fcd4da961960ad0e67a9d1169b41ca2 Mon Sep 17 00:00:00 2001 From: cjprinse Date: Mon, 16 Apr 2018 12:28:35 +0200 Subject: [PATCH 1/3] Update JmsJsonType.php null values in database gives exception --- src/DBAL/JmsJsonType.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DBAL/JmsJsonType.php b/src/DBAL/JmsJsonType.php index 4a63f55..f5f7c1a 100644 --- a/src/DBAL/JmsJsonType.php +++ b/src/DBAL/JmsJsonType.php @@ -72,6 +72,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { + if($value === null) { + return null; + } + @list($type, $json) = explode('::', $value, 2); $phpValue = $this->serializer()->deserialize($json, $type, 'json'); From 90540573576bcaecb8a69a695f7265be8ca455cb Mon Sep 17 00:00:00 2001 From: Christ-Jan Date: Mon, 23 Apr 2018 11:49:45 +0200 Subject: [PATCH 2/3] add null test --- tests/DBAL/JmsJsonTypeFunctionalTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/DBAL/JmsJsonTypeFunctionalTest.php b/tests/DBAL/JmsJsonTypeFunctionalTest.php index 93fd627..c4be628 100644 --- a/tests/DBAL/JmsJsonTypeFunctionalTest.php +++ b/tests/DBAL/JmsJsonTypeFunctionalTest.php @@ -89,6 +89,7 @@ public function values() $date = new \DateTime(); return array( + array(null, null), array(1, 'integer::1'), array(1.25, 'double::1.25'), array(true, 'boolean::true'), From 164d1a554630e316c5b0a911393543d92398177d Mon Sep 17 00:00:00 2001 From: Christ-Jan Date: Mon, 23 Apr 2018 11:54:27 +0200 Subject: [PATCH 3/3] add missing unittests --- tests/DBAL/JmsJsonTypeTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/DBAL/JmsJsonTypeTest.php b/tests/DBAL/JmsJsonTypeTest.php index be186b4..2945045 100644 --- a/tests/DBAL/JmsJsonTypeTest.php +++ b/tests/DBAL/JmsJsonTypeTest.php @@ -102,6 +102,32 @@ public function shouldConvertToDatabaseValueUsingSerializer() ); } + /** + * @test + */ + public function shouldNotConvertNullToDatabaseValue() + { + $this->initializeJmsJsonType($this->serializer, $this->typeResolver); + + $value = null; + $databaseValue = null; + + $this->assertEquals($value, $this->type->convertToDatabaseValue($databaseValue, $this->platform)); + } + + /** + * @test + */ + public function shouldNotConvertNullToPhpValue() + { + $this->initializeJmsJsonType($this->serializer, $this->typeResolver); + + $value = null; + $databaseValue = null; + + $this->assertEquals($value, $this->type->convertToPHPValue($databaseValue, $this->platform)); + } + /** * @test */