From 61eda85b7da8f658b0c334f3ca744af180dfc784 Mon Sep 17 00:00:00 2001
From: Joan He <johe@magento.com>
Date: Fri, 4 Nov 2016 15:46:16 -0500
Subject: [PATCH] MAGETWO-59444: Create serializer interface and json class in
 framework

---
 .../Framework/Serialize/Serializer/Json.php   |  4 ++
 .../Serialize/SerializerInterface.php         |  3 +
 .../Test/Unit/Serializer/JsonTest.php         | 55 +++++++++++++++----
 3 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/lib/internal/Magento/Framework/Serialize/Serializer/Json.php b/lib/internal/Magento/Framework/Serialize/Serializer/Json.php
index 009fee5e363..bf7a34c21fb 100644
--- a/lib/internal/Magento/Framework/Serialize/Serializer/Json.php
+++ b/lib/internal/Magento/Framework/Serialize/Serializer/Json.php
@@ -7,6 +7,10 @@ namespace Magento\Framework\Serialize\Serializer;
 
 use Magento\Framework\Serialize\SerializerInterface;
 
+/**
+ * Class for serializing data to json string and unserializing json string to data
+ *
+ */
 class Json implements SerializerInterface
 {
     /**
diff --git a/lib/internal/Magento/Framework/Serialize/SerializerInterface.php b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php
index 1dc70da80f3..f7a15b31a82 100644
--- a/lib/internal/Magento/Framework/Serialize/SerializerInterface.php
+++ b/lib/internal/Magento/Framework/Serialize/SerializerInterface.php
@@ -5,6 +5,9 @@
  */
 namespace Magento\Framework\Serialize;
 
+/**
+ * Interface for serializing
+ */
 interface SerializerInterface
 {
     /**
diff --git a/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php b/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php
index 38fa7d2a66f..88e06d89e37 100644
--- a/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php
+++ b/lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php
@@ -5,6 +5,7 @@
  */
 namespace Magento\Framework\Serialize\Test\Unit\Serializer;
 
+use Magento\Framework\DataObject;
 use Magento\Framework\Serialize\Serializer\Json;
 
 class JsonTest extends \PHPUnit_Framework_TestCase
@@ -21,25 +22,57 @@ class JsonTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @param null|bool|array $value
-     * @dataProvider serializeUnserializeDataProvider
+     * @param string|int|float|bool|array|null $value
+     * @param string $expected
+     * @dataProvider serializeDataProvider
      */
-    public function testSerializeUnserialize($value)
+    public function testSerialize($value, $expected)
     {
         $this->assertEquals(
-            $this->json->unserialize($this->json->serialize($value)),
-            $value
+            $expected,
+            $this->json->serialize($value)
         );
     }
 
-    public function serializeUnserializeDataProvider()
+    public function serializeDataProvider()
     {
+        $dataObject = new DataObject(['something']);
         return [
-            [''],
-            ['string'],
-            [null],
-            [false],
-            [['a' => 'b']],
+            ['', '""'],
+            ['string', '"string"'],
+            [null, 'null'],
+            [false, 'false'],
+            [['a' => 'b', 'd' => 123], '{"a":"b","d":123}'],
+            [123, '123'],
+            [10.56, '10.56'],
+            [$dataObject, '{}'],
+        ];
+    }
+
+    /**
+     * @param string $value
+     * @param string|int|float|bool|array|null $expected
+     * @dataProvider unserializeDataProvider
+     */
+    public function testUnserialize($value, $expected)
+    {
+        $this->assertEquals(
+            $expected,
+            $this->json->unserialize($value)
+        );
+    }
+
+    public function unserializeDataProvider()
+    {
+        return [
+            ['""', ''],
+            ['"string"', 'string'],
+            ['null', null],
+            ['false', false],
+            ['{"a":"b","d":123}', ['a' => 'b', 'd' => 123]],
+            ['123', 123],
+            ['10.56', 10.56],
+            ['{}', []],
         ];
     }
 }
-- 
GitLab