Skip to content

Commit f01776e

Browse files
committed
Update RedirectTest.php
1 parent 5fc9807 commit f01776e

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Store\Test\Unit\Controller\Store;
99

10+
use Magento\Framework\App\Action\Context;
1011
use Magento\Framework\App\ActionInterface;
1112
use Magento\Framework\App\RequestInterface;
1213
use Magento\Framework\App\Response\RedirectInterface;
@@ -117,18 +118,23 @@ protected function setUp()
117118
->willReturnSelf();
118119

119120
$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+
);
121129
$this->redirectController = $objectManager->getObject(
122130
Redirect::class,
123131
[
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,
132138
]
133139
);
134140
}
@@ -146,13 +152,16 @@ protected function setUp()
146152
public function testRedirect(string $defaultStoreViewCode, string $storeCode): void
147153
{
148154
$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
156165
);
157166
$this->storeRepositoryMock
158167
->expects($this->once())
@@ -162,7 +171,7 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
162171
$this->formStoreMock
163172
->expects($this->once())
164173
->method('getCode')
165-
->willReturnSelf();
174+
->willReturn($defaultStoreViewCode);
166175
$this->sidResolverMock
167176
->expects($this->once())
168177
->method('getUseSessionInUrl')
@@ -172,7 +181,6 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
172181
->method('generateHash')
173182
->with($this->formStoreMock)
174183
->willReturn([]);
175-
176184
$this->redirectMock
177185
->expects($this->once())
178186
->method('redirect')
@@ -182,12 +190,11 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
182190
['_nosid' => true,
183191
'_query' => [
184192
'uenc' => $defaultStoreViewCode,
185-
'___from_store' => $this->formStoreMock,
193+
'___from_store' => $defaultStoreViewCode,
186194
'___store' => $storeCode
187195
]
188196
]
189-
)
190-
->willReturnSelf();
197+
);
191198

192199
$this->assertEquals(null, $this->redirectController->execute());
193200
}
@@ -204,15 +211,13 @@ public function testRedirect(string $defaultStoreViewCode, string $storeCode): v
204211
public function testRedirectWithThrowsException(string $defaultStoreViewCode, string $storeCode): void
205212
{
206213
$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+
);
216221
$this->storeRepositoryMock
217222
->expects($this->once())
218223
->method('get')
@@ -269,7 +274,7 @@ public function testRedirectTargetIsNull(): void
269274
public function getConfigDataProvider(): array
270275
{
271276
return [
272-
[ self::DEFAULT_STORE_VIEW_CODE, self::STORE_CODE ]
277+
[self::DEFAULT_STORE_VIEW_CODE, self::STORE_CODE]
273278
];
274279
}
275280
}

0 commit comments

Comments
 (0)