@@ -37,8 +37,8 @@ class MessagePluginTest extends \PHPUnit_Framework_TestCase
37
37
/** @var InterpretationStrategyInterface|\PHPUnit_Framework_MockObject_MockObject */
38
38
protected $ interpretationStrategyMock ;
39
39
40
- /** @var Data |\PHPUnit_Framework_MockObject_MockObject */
41
- protected $ dataMock ;
40
+ /** @var \Magento\Framework\Serialize\Serializer\Json |\PHPUnit_Framework_MockObject_MockObject */
41
+ private $ serializerMock ;
42
42
43
43
protected function setUp ()
44
44
{
@@ -51,16 +51,15 @@ protected function setUp()
51
51
->getMockForAbstractClass ();
52
52
$ this ->interpretationStrategyMock = $ this ->getMockBuilder (InterpretationStrategyInterface::class)
53
53
->getMockForAbstractClass ();
54
- $ this ->dataMock = $ this ->getMockBuilder (Data::class)
55
- ->disableOriginalConstructor ()
54
+ $ this ->serializerMock = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
56
55
->getMock ();
57
56
58
57
$ this ->model = new MessagePlugin (
59
58
$ this ->cookieManagerMock ,
60
59
$ this ->cookieMetadataFactoryMock ,
61
60
$ this ->managerMock ,
62
61
$ this ->interpretationStrategyMock ,
63
- $ this ->dataMock
62
+ $ this ->serializerMock
64
63
);
65
64
}
66
65
@@ -113,29 +112,29 @@ public function testAfterRenderResult()
113
112
->method ('setPublicCookie ' )
114
113
->with (
115
114
MessagePlugin::MESSAGES_COOKIES_NAME ,
116
- \Zend_Json:: encode ($ messages ),
115
+ json_encode ($ messages ),
117
116
$ cookieMetadataMock
118
117
);
119
118
$ this ->cookieManagerMock ->expects ($ this ->once ())
120
119
->method ('getCookie ' )
121
120
->with (
122
121
MessagePlugin::MESSAGES_COOKIES_NAME ,
123
- \Zend_Json:: encode ([])
122
+ json_encode ([])
124
123
)
125
- ->willReturn (\Zend_Json:: encode ($ existingMessages ));
124
+ ->willReturn (json_encode ($ existingMessages ));
126
125
127
- $ this ->dataMock ->expects ($ this ->once ())
128
- ->method ('jsonDecode ' )
126
+ $ this ->serializerMock ->expects ($ this ->once ())
127
+ ->method ('unserialize ' )
129
128
->willReturnCallback (
130
129
function ($ data ) {
131
- return \Zend_Json:: decode ($ data );
130
+ return json_decode ($ data, true );
132
131
}
133
132
);
134
- $ this ->dataMock ->expects ($ this ->exactly (2 ))
135
- ->method ('jsonEncode ' )
133
+ $ this ->serializerMock ->expects ($ this ->exactly (2 ))
134
+ ->method ('serialize ' )
136
135
->willReturnCallback (
137
136
function ($ data ) {
138
- return \Zend_Json:: encode ($ data );
137
+ return json_encode ($ data );
139
138
}
140
139
);
141
140
@@ -178,22 +177,22 @@ public function testAfterRenderResultWithNoMessages()
178
177
->method ('getCookie ' )
179
178
->with (
180
179
MessagePlugin::MESSAGES_COOKIES_NAME ,
181
- \Zend_Json:: encode ([])
180
+ json_encode ([])
182
181
)
183
- ->willReturn (\Zend_Json:: encode ([]));
182
+ ->willReturn (json_encode ([]));
184
183
185
- $ this ->dataMock ->expects ($ this ->once ())
186
- ->method ('jsonDecode ' )
184
+ $ this ->serializerMock ->expects ($ this ->once ())
185
+ ->method ('unserialize ' )
187
186
->willReturnCallback (
188
187
function ($ data ) {
189
- return \Zend_Json:: decode ($ data );
188
+ return json_decode ($ data, true );
190
189
}
191
190
);
192
- $ this ->dataMock ->expects ($ this ->once ())
193
- ->method ('jsonEncode ' )
191
+ $ this ->serializerMock ->expects ($ this ->once ())
192
+ ->method ('serialize ' )
194
193
->willReturnCallback (
195
194
function ($ data ) {
196
- return \Zend_Json:: encode ($ data );
195
+ return json_encode ($ data );
197
196
}
198
197
);
199
198
@@ -246,29 +245,29 @@ public function testAfterRenderResultWithoutExisting()
246
245
->method ('setPublicCookie ' )
247
246
->with (
248
247
MessagePlugin::MESSAGES_COOKIES_NAME ,
249
- \Zend_Json:: encode ($ messages ),
248
+ json_encode ($ messages ),
250
249
$ cookieMetadataMock
251
250
);
252
251
$ this ->cookieManagerMock ->expects ($ this ->once ())
253
252
->method ('getCookie ' )
254
253
->with (
255
254
MessagePlugin::MESSAGES_COOKIES_NAME ,
256
- \Zend_Json:: encode ([])
255
+ json_encode ([])
257
256
)
258
- ->willReturn (\Zend_Json:: encode ([]));
257
+ ->willReturn (json_encode ([]));
259
258
260
- $ this ->dataMock ->expects ($ this ->any ())
261
- ->method ('jsonDecode ' )
259
+ $ this ->serializerMock ->expects ($ this ->once ())
260
+ ->method ('unserialize ' )
262
261
->willReturnCallback (
263
262
function ($ data ) {
264
- return \Zend_Json:: decode ($ data );
263
+ return json_decode ($ data, true );
265
264
}
266
265
);
267
- $ this ->dataMock ->expects ($ this ->any ( ))
268
- ->method ('jsonEncode ' )
266
+ $ this ->serializerMock ->expects ($ this ->exactly ( 2 ))
267
+ ->method ('serialize ' )
269
268
->willReturnCallback (
270
269
function ($ data ) {
271
- return \Zend_Json:: encode ($ data );
270
+ return json_encode ($ data );
272
271
}
273
272
);
274
273
@@ -329,25 +328,29 @@ public function testAfterRenderResultWithWrongJson()
329
328
->method ('setPublicCookie ' )
330
329
->with (
331
330
MessagePlugin::MESSAGES_COOKIES_NAME ,
332
- \Zend_Json:: encode ($ messages ),
331
+ json_encode ($ messages ),
333
332
$ cookieMetadataMock
334
333
);
335
334
$ this ->cookieManagerMock ->expects ($ this ->once ())
336
335
->method ('getCookie ' )
337
336
->with (
338
337
MessagePlugin::MESSAGES_COOKIES_NAME ,
339
- \Zend_Json:: encode ([])
338
+ json_encode ([])
340
339
)
341
- ->willReturn (\Zend_Json:: encode ([]));
340
+ ->willReturn (json_encode ([]));
342
341
343
- $ this ->dataMock ->expects ($ this ->any ())
344
- ->method ('jsonDecode ' )
345
- ->willThrowException (new \Zend_Json_Exception );
346
- $ this ->dataMock ->expects ($ this ->any ())
347
- ->method ('jsonEncode ' )
342
+ $ this ->serializerMock ->expects ($ this ->once ())
343
+ ->method ('unserialize ' )
344
+ ->willReturnCallback (
345
+ function ($ data ) {
346
+ return json_decode ($ data , true );
347
+ }
348
+ );
349
+ $ this ->serializerMock ->expects ($ this ->exactly (2 ))
350
+ ->method ('serialize ' )
348
351
->willReturnCallback (
349
352
function ($ data ) {
350
- return \Zend_Json:: encode ($ data );
353
+ return json_encode ($ data );
351
354
}
352
355
);
353
356
@@ -408,29 +411,29 @@ public function testAfterRenderResultWithWrongArray()
408
411
->method ('setPublicCookie ' )
409
412
->with (
410
413
MessagePlugin::MESSAGES_COOKIES_NAME ,
411
- \Zend_Json:: encode ($ messages ),
414
+ json_encode ($ messages ),
412
415
$ cookieMetadataMock
413
416
);
414
417
$ this ->cookieManagerMock ->expects ($ this ->once ())
415
418
->method ('getCookie ' )
416
419
->with (
417
420
MessagePlugin::MESSAGES_COOKIES_NAME ,
418
- \Zend_Json:: encode ([])
421
+ json_encode ([])
419
422
)
420
- ->willReturn (\Zend_Json:: encode ('string ' ));
423
+ ->willReturn (json_encode ('string ' ));
421
424
422
- $ this ->dataMock ->expects ($ this ->any ())
423
- ->method ('jsonDecode ' )
425
+ $ this ->serializerMock ->expects ($ this ->once ())
426
+ ->method ('unserialize ' )
424
427
->willReturnCallback (
425
428
function ($ data ) {
426
- return \Zend_Json:: decode ($ data );
429
+ return json_decode ($ data, true );
427
430
}
428
431
);
429
- $ this ->dataMock ->expects ($ this ->any ( ))
430
- ->method ('jsonEncode ' )
432
+ $ this ->serializerMock ->expects ($ this ->exactly ( 2 ))
433
+ ->method ('serialize ' )
431
434
->willReturnCallback (
432
435
function ($ data ) {
433
- return \Zend_Json:: encode ($ data );
436
+ return json_encode ($ data );
434
437
}
435
438
);
436
439
0 commit comments