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