1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Tests\Serializers;
6
7use Elasticsearch\Serializers\ArrayToJSONSerializer;
8use Mockery as m;
9
10/**
11 * Class ArrayToJSONSerializerTest
12 *
13 * @package Elasticsearch\Tests\Serializers
14 */
15class ArrayToJSONSerializerTest extends \PHPUnit\Framework\TestCase
16{
17    public function tearDown()
18    {
19        m::close();
20    }
21
22    public function testSerializeArray()
23    {
24        $serializer = new ArrayToJSONSerializer();
25        $body = ['value' => 'field'];
26
27        $ret = $serializer->serialize($body);
28
29        $body = json_encode($body, JSON_PRESERVE_ZERO_FRACTION);
30        $this->assertSame($body, $ret);
31    }
32
33    public function testSerializeString()
34    {
35        $serializer = new ArrayToJSONSerializer();
36        $body = 'abc';
37
38        $ret = $serializer->serialize($body);
39
40        $this->assertSame($body, $ret);
41    }
42
43    public function testDeserializeJSON()
44    {
45        $serializer = new ArrayToJSONSerializer();
46        $body = '{"field":"value"}';
47
48        $ret = $serializer->deserialize($body, []);
49
50        $body = json_decode($body, true);
51        $this->assertSame($body, $ret);
52    }
53}
54