@@ -79,7 +79,6 @@ public function testAfterRenderResultJson()
79
79
80
80
public function testAfterRenderResult ()
81
81
{
82
-
83
82
$ existingMessages = [
84
83
[
85
84
'type ' => 'message0type ' ,
@@ -125,14 +124,14 @@ public function testAfterRenderResult()
125
124
)
126
125
->willReturn (\Zend_Json::encode ($ existingMessages ));
127
126
128
- $ this ->dataMock ->expects ($ this ->any ())
127
+ $ this ->dataMock ->expects ($ this ->once ())
129
128
->method ('jsonDecode ' )
130
129
->willReturnCallback (
131
130
function ($ data ) {
132
131
return \Zend_Json::decode ($ data );
133
132
}
134
133
);
135
- $ this ->dataMock ->expects ($ this ->any ( ))
134
+ $ this ->dataMock ->expects ($ this ->exactly ( 2 ))
136
135
->method ('jsonEncode ' )
137
136
->willReturnCallback (
138
137
function ($ data ) {
@@ -168,6 +167,56 @@ function ($data) {
168
167
$ this ->assertEquals ($ resultMock , $ this ->model ->afterRenderResult ($ resultMock , $ resultMock ));
169
168
}
170
169
170
+ public function testAfterRenderResultWithNoMessages ()
171
+ {
172
+ /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */
173
+ $ resultMock = $ this ->getMockBuilder (Redirect::class)
174
+ ->disableOriginalConstructor ()
175
+ ->getMock ();
176
+
177
+ $ this ->cookieManagerMock ->expects ($ this ->once ())
178
+ ->method ('getCookie ' )
179
+ ->with (
180
+ MessagePlugin::MESSAGES_COOKIES_NAME ,
181
+ \Zend_Json::encode ([])
182
+ )
183
+ ->willReturn (\Zend_Json::encode ([]));
184
+
185
+ $ this ->dataMock ->expects ($ this ->once ())
186
+ ->method ('jsonDecode ' )
187
+ ->willReturnCallback (
188
+ function ($ data ) {
189
+ return \Zend_Json::decode ($ data );
190
+ }
191
+ );
192
+ $ this ->dataMock ->expects ($ this ->once ())
193
+ ->method ('jsonEncode ' )
194
+ ->willReturnCallback (
195
+ function ($ data ) {
196
+ return \Zend_Json::encode ($ data );
197
+ }
198
+ );
199
+
200
+ /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
201
+ $ collectionMock = $ this ->getMockBuilder (Collection::class)
202
+ ->disableOriginalConstructor ()
203
+ ->getMock ();
204
+ $ collectionMock ->expects ($ this ->once ())
205
+ ->method ('getItems ' )
206
+ ->willReturn ([]);
207
+
208
+ $ this ->managerMock ->expects ($ this ->once ())
209
+ ->method ('getMessages ' )
210
+ ->with (true , null )
211
+ ->willReturn ($ collectionMock );
212
+
213
+ $ this ->cookieMetadataFactoryMock ->expects ($ this ->never ())
214
+ ->method ('createPublicCookieMetadata ' )
215
+ ->willReturn (null );
216
+
217
+ $ this ->assertEquals ($ resultMock , $ this ->model ->afterRenderResult ($ resultMock , $ resultMock ));
218
+ }
219
+
171
220
public function testAfterRenderResultWithoutExisting ()
172
221
{
173
222
$ messageType = 'message1type ' ;
0 commit comments