1
0
mirror of synced 2024-12-01 09:06:03 +03:00
service-bundle/Tests/Serializer/SymfonySerializerAdapterTest.php

41 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace RetailCrm\ServiceBundle\Tests\Serializer;
use PHPUnit\Framework\TestCase;
use RetailCrm\ServiceBundle\Serializer\SymfonySerializerAdapter;
use RetailCrm\ServiceBundle\Tests\DataFixtures\RequestDto;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
class SymfonySerializerAdapterTest extends TestCase
{
private $serializer;
private $denormalizer;
protected function setUp(): void
{
$this->serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
$this->denormalizer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
}
public function testDeserialize(): void
{
$adapter = new SymfonySerializerAdapter($this->serializer, $this->denormalizer);
$object = $adapter->deserialize('{"param": "string"}', RequestDto::class,'json');
static::assertInstanceOf(RequestDto::class, $object);
static::assertEquals('string', $object->param);
}
public function testArrayToObject(): void
{
$adapter = new SymfonySerializerAdapter($this->serializer, $this->denormalizer);
$object = $adapter->arrayToObject(['param' => 'string'], RequestDto::class);
static::assertInstanceOf(RequestDto::class, $object);
static::assertEquals('string', $object->param);
}
}