ref #79146 keeping falsy-values when deserialize
This commit is contained in:
parent
98563e2e60
commit
3047d2db00
2 changed files with 59 additions and 1 deletions
|
@ -73,8 +73,11 @@ class Serializer
|
|||
if ($context instanceof DeserializationContext) {
|
||||
switch ($from) {
|
||||
case self::S_ARRAY:
|
||||
$filtered = array_filter($data, static function ($el) {
|
||||
return isset($el);
|
||||
});
|
||||
$deserialized = $serializer
|
||||
->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
|
||||
->fromArray($filtered, self::normalizeNamespace($entityType), $context);
|
||||
break;
|
||||
case self::S_JSON:
|
||||
$deserialized = $serializer
|
||||
|
|
55
tests/Bot/Tests/Model/MessageTest.php
Normal file
55
tests/Bot/Tests/Model/MessageTest.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Tests\Model;
|
||||
|
||||
use RetailCrm\Common\Serializer;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MessageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataProvider_noContent
|
||||
* @param $content
|
||||
*/
|
||||
public function testDeserialization_NoContent($content): void
|
||||
{
|
||||
$item = ['content' => $content];
|
||||
|
||||
/** @var Message $result */
|
||||
$result = Serializer::deserialize($item, Message::class, Serializer::S_ARRAY);
|
||||
|
||||
self::assertNull($result->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider_withContent
|
||||
* @param $content
|
||||
*/
|
||||
public function testDeserialization_WithContent($content): void
|
||||
{
|
||||
$item = ['content' => $content];
|
||||
|
||||
/** @var Message $result */
|
||||
$result = Serializer::deserialize($item, Message::class, Serializer::S_ARRAY);
|
||||
|
||||
self::assertNotNull($result->getContent());
|
||||
self::assertEquals($content, $result->getContent());
|
||||
}
|
||||
|
||||
public function dataProvider_noContent(): array
|
||||
{
|
||||
return [
|
||||
[null],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataProvider_withContent(): array
|
||||
{
|
||||
return [
|
||||
[''],
|
||||
['0'],
|
||||
['Something'],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue