|
8 | 8 | use Magento\Framework\Serialize\Serializer\Serialize;
|
9 | 9 | use Magento\Framework\Serialize\Serializer\Json;
|
10 | 10 | use Magento\Framework\DB\DataConverter\SerializedToJson;
|
11 |
| -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
12 | 11 |
|
13 | 12 | class SerializedToJsonTest extends \PHPUnit\Framework\TestCase
|
14 | 13 | {
|
15 |
| - /** |
16 |
| - * @var Serialize|\PHPUnit_Framework_MockObject_MockObject |
17 |
| - */ |
18 |
| - private $serializeMock; |
19 |
| - |
20 |
| - /** |
21 |
| - * @var Json|\PHPUnit_Framework_MockObject_MockObject |
22 |
| - */ |
23 |
| - private $jsonMock; |
24 |
| - |
25 | 14 | /**
|
26 | 15 | * @var SerializedToJson
|
27 | 16 | */
|
28 | 17 | private $serializedToJson;
|
29 | 18 |
|
30 | 19 | protected function setUp()
|
31 | 20 | {
|
32 |
| - $objectManager = new ObjectManager($this); |
33 |
| - $this->serializeMock = $this->createMock(Serialize::class); |
34 |
| - $this->jsonMock = $this->createMock(Json::class); |
35 |
| - $this->serializedToJson = $objectManager->getObject( |
36 |
| - SerializedToJson::class, |
37 |
| - [ |
38 |
| - 'serialize' => $this->serializeMock, |
39 |
| - 'json' => $this->jsonMock |
40 |
| - ] |
| 21 | + $this->serializedToJson = new SerializedToJson( |
| 22 | + new Serialize(), |
| 23 | + new Json() |
41 | 24 | );
|
42 | 25 | }
|
43 | 26 |
|
44 |
| - public function testConvert() |
| 27 | + /** |
| 28 | + * Tests converting from serialized to JSON format with different precision settings. |
| 29 | + * |
| 30 | + * @param $serializedData |
| 31 | + * @param $expectedJson |
| 32 | + * @dataProvider convertDataProvider |
| 33 | + */ |
| 34 | + public function testConvert($serializedData, $expectedJson) |
| 35 | + { |
| 36 | + $this->assertEquals($expectedJson, $this->serializedToJson->convert($serializedData)); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @case #1 - Serialized 0.1234567890123456789 with serialize_precision = 17 (default for PHP version < 7.1.0) |
| 41 | + * @case #2 - Serialized 2.203 with serialize_precision = 17 (default for PHP version < 7.1.0 ) |
| 42 | + * @return array |
| 43 | + */ |
| 44 | + public function convertDataProvider() |
45 | 45 | {
|
46 |
| - $serializedData = 'serialized data'; |
47 |
| - $jsonData = 'json data'; |
48 |
| - $unserializedData = 'unserialized data'; |
49 |
| - $this->serializeMock->expects($this->once()) |
50 |
| - ->method('unserialize') |
51 |
| - ->with($serializedData) |
52 |
| - ->willReturn($unserializedData); |
53 |
| - $this->jsonMock->expects($this->once()) |
54 |
| - ->method('serialize') |
55 |
| - ->with($unserializedData) |
56 |
| - ->willReturn($jsonData); |
57 |
| - $this->assertEquals($jsonData, $this->serializedToJson->convert($serializedData)); |
| 46 | + return [ |
| 47 | + 1 => ['serializedData' => 'a:1:{i:0;d:0.12345678901234568;}', 'expectedJson' => '[0.12345678901234568]'], |
| 48 | + 2 => ['serializedData' => 'a:1:{i:0;d:2.2029999999999998;}', 'expectedJson' => '[2.2029999999999998]'] |
| 49 | + ]; |
58 | 50 | }
|
59 | 51 | }
|
0 commit comments