7
7
8
8
namespace Magento \Store \Test \Unit \Controller \Store ;
9
9
10
+ use Magento \Framework \App \Action \Context ;
10
11
use Magento \Framework \App \ActionInterface ;
11
12
use Magento \Framework \App \RequestInterface ;
12
13
use Magento \Framework \App \Response \RedirectInterface ;
@@ -117,18 +118,23 @@ protected function setUp()
117
118
->willReturnSelf ();
118
119
119
120
$ objectManager = new ObjectManagerHelper ($ this );
120
-
121
+ $ context = $ objectManager ->getObject (
122
+ Context::class,
123
+ [
124
+ '_request ' => $ this ->requestMock ,
125
+ '_redirect ' => $ this ->redirectMock ,
126
+ '_response ' => $ this ->responseMock ,
127
+ ]
128
+ );
121
129
$ this ->redirectController = $ objectManager ->getObject (
122
130
Redirect::class,
123
131
[
124
- 'storeRepository ' => $ this ->storeRepositoryMock ,
125
- 'storeResolver ' => $ this ->storeResolverMock ,
126
- 'messageManager ' => $ this ->messageManagerMock ,
127
- '_request ' => $ this ->requestMock ,
128
- '_redirect ' => $ this ->redirectMock ,
129
- '_response ' => $ this ->responseMock ,
130
- 'sidResolver ' => $ this ->sidResolverMock ,
131
- 'hashGenerator ' => $ this ->hashGeneratorMock
132
+ 'storeRepository ' => $ this ->storeRepositoryMock ,
133
+ 'storeResolver ' => $ this ->storeResolverMock ,
134
+ 'messageManager ' => $ this ->messageManagerMock ,
135
+ 'sidResolver ' => $ this ->sidResolverMock ,
136
+ 'hashGenerator ' => $ this ->hashGeneratorMock ,
137
+ 'context ' => $ context ,
132
138
]
133
139
);
134
140
}
@@ -146,13 +152,16 @@ protected function setUp()
146
152
public function testRedirect (string $ defaultStoreViewCode , string $ storeCode ): void
147
153
{
148
154
$ this ->requestMock
149
- ->expects ($ this ->any ())
150
- ->method ('getParam ' )->willReturnMap (
151
- [
152
- [StoreResolver::PARAM_NAME , null , $ storeCode ],
153
- ['___from_store ' , null , $ defaultStoreViewCode ],
154
- [ActionInterface::PARAM_NAME_URL_ENCODED , null , $ defaultStoreViewCode ]
155
- ]
155
+ ->expects ($ this ->exactly (3 ))
156
+ ->method ('getParam ' )
157
+ ->withConsecutive (
158
+ [StoreResolver::PARAM_NAME ],
159
+ ['___from_store ' ],
160
+ [ActionInterface::PARAM_NAME_URL_ENCODED ]
161
+ )->willReturnOnConsecutiveCalls (
162
+ $ storeCode ,
163
+ $ defaultStoreViewCode ,
164
+ $ defaultStoreViewCode
156
165
);
157
166
$ this ->storeRepositoryMock
158
167
->expects ($ this ->once ())
@@ -162,7 +171,7 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
162
171
$ this ->formStoreMock
163
172
->expects ($ this ->once ())
164
173
->method ('getCode ' )
165
- ->willReturnSelf ( );
174
+ ->willReturn ( $ defaultStoreViewCode );
166
175
$ this ->sidResolverMock
167
176
->expects ($ this ->once ())
168
177
->method ('getUseSessionInUrl ' )
@@ -172,7 +181,6 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
172
181
->method ('generateHash ' )
173
182
->with ($ this ->formStoreMock )
174
183
->willReturn ([]);
175
-
176
184
$ this ->redirectMock
177
185
->expects ($ this ->once ())
178
186
->method ('redirect ' )
@@ -182,12 +190,11 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
182
190
['_nosid ' => true ,
183
191
'_query ' => [
184
192
'uenc ' => $ defaultStoreViewCode ,
185
- '___from_store ' => $ this -> formStoreMock ,
193
+ '___from_store ' => $ defaultStoreViewCode ,
186
194
'___store ' => $ storeCode
187
195
]
188
196
]
189
- )
190
- ->willReturnSelf ();
197
+ );
191
198
192
199
$ this ->assertEquals (null , $ this ->redirectController ->execute ());
193
200
}
@@ -204,15 +211,13 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
204
211
public function testRedirectWithThrowsException (string $ defaultStoreViewCode , string $ storeCode ): void
205
212
{
206
213
$ this ->requestMock
207
- ->expects ($ this ->at (0 ))
208
- ->method ('getParam ' )
209
- ->with (StoreResolver::PARAM_NAME )
210
- ->willReturn ($ storeCode );
211
- $ this ->requestMock
212
- ->expects ($ this ->at (1 ))
213
- ->method ('getParam ' )
214
- ->with ('___from_store ' )
215
- ->willReturn ($ defaultStoreViewCode );
214
+ ->expects ($ this ->exactly (2 ))
215
+ ->method ('getParam ' )->willReturnMap (
216
+ [
217
+ [StoreResolver::PARAM_NAME , null , $ storeCode ],
218
+ ['___from_store ' , null , $ defaultStoreViewCode ]
219
+ ]
220
+ );
216
221
$ this ->storeRepositoryMock
217
222
->expects ($ this ->once ())
218
223
->method ('get ' )
@@ -269,7 +274,7 @@ public function testRedirectTargetIsNull(): void
269
274
public function getConfigDataProvider (): array
270
275
{
271
276
return [
272
- [ self ::DEFAULT_STORE_VIEW_CODE , self ::STORE_CODE ]
277
+ [self ::DEFAULT_STORE_VIEW_CODE , self ::STORE_CODE ]
273
278
];
274
279
}
275
280
}
0 commit comments