1
0
mirror of synced 2024-11-25 06:16:06 +03:00
service-bundle/Tests/Serializer/SymfonySerializerAdapterTest.php
Akolzin Dmitry 7516ec60cb
JMS serializer supports (#3)
* add callback argument value resolver
* add jms serializer support
* add phpdoc
* fix FrontApiClientAuthenticator
2021-02-17 09:31:36 +03:00

41 lines
1.4 KiB
PHP

<?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);
}
}