Skip to content
Snippets Groups Projects
Commit dddb34e5 authored by Joan He's avatar Joan He
Browse files

MAGETWO-59444: Create serializer interface and json class in framework

- Address code review comments
parent 4efeb173
Branches
No related merge requests found
......@@ -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
......@@ -22,24 +23,54 @@ class JsonTest extends \PHPUnit_Framework_TestCase
/**
* @param null|bool|array $value
* @dataProvider serializeUnserializeDataProvider
* @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 null|bool|array $value
* @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],
['{}', []],
];
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment