Skip to content

Commit

Permalink
Merge pull request #1 from cjprinse/patch-1
Browse files Browse the repository at this point in the history
Update JmsJsonType.php
  • Loading branch information
Daniel Bojdo authored Apr 23, 2018
2 parents 5e428c5 + 164d1a5 commit 33f78cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DBAL/JmsJsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions tests/DBAL/JmsJsonTypeFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
26 changes: 26 additions & 0 deletions tests/DBAL/JmsJsonTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 33f78cf

Please sign in to comment.