Skip to content

Commit cea0c66

Browse files
committed
Fix RedirectTest
1 parent f01776e commit cea0c66

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

app/code/Magento/Store/Test/Unit/Controller/Store/RedirectTest.php

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,34 @@ class RedirectTest extends TestCase
9494
*/
9595
protected function setUp()
9696
{
97-
$this->requestMock = $this->createMock(RequestInterface::class);
98-
$this->redirectMock = $this->createMock(RedirectInterface::class);
99-
$this->storeResolverMock = $this->createMock(StoreResolverInterface::class);
100-
$this->storeRepositoryMock = $this->createMock(StoreRepositoryInterface::class);
101-
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
102-
$this->responseMock = $this->createMock(ResponseInterface::class);
97+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
98+
->disableOriginalConstructor()
99+
->setMethods(['getParam'])
100+
->getMockForAbstractClass();
101+
$this->redirectMock = $this->getMockBuilder(RedirectInterface::class)
102+
->disableOriginalConstructor()
103+
->setMethods(['redirect'])
104+
->getMockForAbstractClass();
105+
$this->storeResolverMock = $this->getMockBuilder(StoreResolverInterface::class)
106+
->disableOriginalConstructor()
107+
->setMethods(['getCurrentStoreId'])
108+
->getMockForAbstractClass();
109+
$this->storeRepositoryMock = $this->getMockBuilder(StoreRepositoryInterface::class)
110+
->disableOriginalConstructor()
111+
->setMethods(['getById', 'get'])
112+
->getMockForAbstractClass();
113+
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
114+
->disableOriginalConstructor()
115+
->setMethods(['addErrorMessage'])
116+
->getMockForAbstractClass();
117+
$this->responseMock = $this->getMockBuilder(ResponseInterface::class)
118+
->disableOriginalConstructor()
119+
->getMockForAbstractClass();
103120
$this->formStoreMock = $this->createMock(Store::class);
104-
$this->sidResolverMock = $this->createMock(SidResolverInterface::class);
121+
$this->sidResolverMock = $this->getMockBuilder(SidResolverInterface::class)
122+
->disableOriginalConstructor()
123+
->setMethods(['getUseSessionInUrl'])
124+
->getMockForAbstractClass();
105125
$this->hashGeneratorMock = $this->createMock(HashGenerator::class);
106126

107127
$this->currentStoreMock = $this->getMockBuilder(Store::class)
@@ -124,14 +144,14 @@ protected function setUp()
124144
'_request' => $this->requestMock,
125145
'_redirect' => $this->redirectMock,
126146
'_response' => $this->responseMock,
147+
'messageManager' => $this->messageManagerMock,
127148
]
128149
);
129150
$this->redirectController = $objectManager->getObject(
130151
Redirect::class,
131152
[
132153
'storeRepository' => $this->storeRepositoryMock,
133154
'storeResolver' => $this->storeResolverMock,
134-
'messageManager' => $this->messageManagerMock,
135155
'sidResolver' => $this->sidResolverMock,
136156
'hashGenerator' => $this->hashGeneratorMock,
137157
'context' => $context,
@@ -147,7 +167,6 @@ protected function setUp()
147167
*
148168
* @dataProvider getConfigDataProvider
149169
* @return void
150-
* @throws NoSuchEntityException
151170
*/
152171
public function testRedirect(string $defaultStoreViewCode, string $storeCode): void
153172
{
@@ -206,17 +225,18 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
206225
* @param string $storeCode
207226
* @return void
208227
* @dataProvider getConfigDataProvider
209-
* @throws NoSuchEntityException
210228
*/
211229
public function testRedirectWithThrowsException(string $defaultStoreViewCode, string $storeCode): void
212230
{
213231
$this->requestMock
214232
->expects($this->exactly(2))
215-
->method('getParam')->willReturnMap(
216-
[
217-
[StoreResolver::PARAM_NAME, null, $storeCode],
218-
['___from_store', null, $defaultStoreViewCode]
219-
]
233+
->method('getParam')
234+
->withConsecutive(
235+
[StoreResolver::PARAM_NAME],
236+
['___from_store']
237+
)->willReturnOnConsecutiveCalls(
238+
$storeCode,
239+
$defaultStoreViewCode
220240
);
221241
$this->storeRepositoryMock
222242
->expects($this->once())
@@ -245,20 +265,19 @@ public function testRedirectWithThrowsException(string $defaultStoreViewCode, st
245265
* Verify redirect target is null
246266
*
247267
* @return void
248-
* @throws NoSuchEntityException
249268
*/
250269
public function testRedirectTargetIsNull(): void
251270
{
252271
$this->requestMock
253-
->expects($this->at(0))
254-
->method('getParam')
255-
->with(StoreResolver::PARAM_NAME)
256-
->willReturn(null);
257-
$this->requestMock
258-
->expects($this->at(1))
272+
->expects($this->exactly(2))
259273
->method('getParam')
260-
->with('___from_store')
261-
->willReturnSelf();
274+
->withConsecutive(
275+
[StoreResolver::PARAM_NAME],
276+
['___from_store']
277+
)->willReturnOnConsecutiveCalls(
278+
null,
279+
null
280+
);
262281
$this->storeRepositoryMock
263282
->expects($this->never())
264283
->method('get');

0 commit comments

Comments
 (0)