@@ -77,6 +77,7 @@ protected function setUp()
77
77
78
78
$ this ->serializer = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
79
79
->disableOriginalConstructor ()
80
+ ->setMethods (['serialize ' , 'unserialize ' ])
80
81
->getMock ();
81
82
82
83
$ this ->urlBuilder = $ this ->getMockBuilder (\Magento \Catalog \Model \Product \Option \UrlBuilder::class)
@@ -99,6 +100,26 @@ protected function setUp()
99
100
'' ,
100
101
false
101
102
);
103
+
104
+ $ this ->serializer ->expects ($ this ->any ())
105
+ ->method ('unserialize ' )
106
+ ->will (
107
+ $ this ->returnCallback (
108
+ function ($ value ) {
109
+ return json_decode ($ value , true );
110
+ }
111
+ )
112
+ );
113
+
114
+ $ this ->serializer ->expects ($ this ->any ())
115
+ ->method ('serialize ' )
116
+ ->will (
117
+ $ this ->returnCallback (
118
+ function ($ value ) {
119
+ return json_encode ($ value );
120
+ }
121
+ )
122
+ );
102
123
}
103
124
104
125
/**
@@ -237,9 +258,6 @@ public function testGetFormattedOptionValue()
237
258
public function testGetFormattedOptionValueInvalid ()
238
259
{
239
260
$ optionValue = 'invalid json option value... ' ;
240
- $ this ->serializer ->expects ($ this ->once ())
241
- ->method ('unserialize ' )
242
- ->willThrowException (new SerializationException (__ ('Invalid JSON value. ' )));
243
261
$ this ->assertEquals ($ optionValue , $ this ->getFileObject ()->getFormattedOptionValue ($ optionValue ));
244
262
}
245
263
@@ -361,25 +379,14 @@ public function testParseOptionValueInvalid()
361
379
->method ('create ' )
362
380
->will ($ this ->returnValue ($ itemMock ));
363
381
364
- $ this ->serializer ->expects ($ this ->once ())
365
- ->method ('unserialize ' )
366
- ->with ($ optionValue )
367
- ->willThrowException (new SerializationException (__ ('Invalid JSON value. ' )));
368
-
369
382
$ this ->assertEquals (null , $ fileObject ->parseOptionValue ($ userInput , []));
370
383
}
371
384
372
385
public function testPrepareOptionValueForRequest ()
373
386
{
374
- $ optionValue = 'string ' ;
375
387
$ resultValue = ['result ' ];
388
+ $ optionValue = json_encode ($ resultValue );
376
389
$ fileObject = $ this ->getFileObject ();
377
-
378
- $ this ->serializer ->expects ($ this ->once ())
379
- ->method ('unserialize ' )
380
- ->with ($ optionValue )
381
- ->willReturn ($ resultValue );
382
-
383
390
$ this ->assertEquals ($ resultValue , $ fileObject ->prepareOptionValueForRequest ($ optionValue ));
384
391
}
385
392
}
0 commit comments