Skip to content

Commit 0cbc5b6

Browse files
Added Const variables and cleanup code
1 parent 392bd3b commit 0cbc5b6

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@
55
*/
66
namespace Magento\Store\Test\Unit\Controller\Store;
77

8+
use Magento\Framework\App\RequestInterface;
9+
use Magento\Framework\App\Response\RedirectInterface;
10+
use Magento\Framework\App\ResponseInterface;
811
use Magento\Store\Api\StoreRepositoryInterface;
912
use Magento\Store\Api\StoreResolverInterface;
13+
use Magento\Store\Controller\Store\Redirect;
1014
use Magento\Store\Model\StoreManagerInterface;
1115
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1216
use Magento\Store\Model\StoreResolver;
17+
use Magento\Store\Api\Data\StoreInterface;
18+
use PHPUnit\Framework\TestCase;
1319

1420
/**
1521
* Test class for \Magento\Store\Controller\Store\SwitchAction
1622
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1723
*/
18-
class RedirectTest extends \PHPUnit\Framework\TestCase
24+
class RedirectTest extends TestCase
1925
{
26+
27+
const STUB_STORE_TO_SWITCH_TO_CODE = 'sv2';
28+
const STUB_DEFAULT_STORE_VIEW = 'default';
29+
2030
/**
2131
* @var \Magento\Store\Controller\Store\SwitchAction
2232
*/
@@ -58,21 +68,21 @@ class RedirectTest extends \PHPUnit\Framework\TestCase
5868
*/
5969
protected function setUp()
6070
{
61-
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)->getMock();
62-
$this->storeRepositoryMock = $this->getMockBuilder(\Magento\Store\Api\StoreRepositoryInterface::class)->getMock();
63-
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
71+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMock();
72+
$this->storeRepositoryMock = $this->getMockBuilder(StoreRepositoryInterface::class)->getMock();
73+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
6474
->disableOriginalConstructor()
6575
->setMethods(['getHttpHost'])
6676
->getMockForAbstractClass();
67-
$this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
77+
$this->responseMock = $this->getMockBuilder(ResponseInterface::class)
6878
->disableOriginalConstructor()
6979
->setMethods(['setRedirect'])
7080
->getMockForAbstractClass();
7181
$this->storeResolverMock = $this->getMockBuilder(StoreResolverInterface::class)->getMock();
72-
$this->redirectMock = $this->getMockBuilder(\Magento\Framework\App\Response\RedirectInterface::class)->getMock();
82+
$this->redirectMock = $this->getMockBuilder(RedirectInterface::class)->getMock();
7383

7484
$this->model = (new ObjectManager($this))->getObject(
75-
\Magento\Store\Controller\Store\Redirect::class,
85+
Redirect::class,
7686
[
7787
'storeRepository' => $this->storeRepositoryMock,
7888
'storeManager' => $this->storeManagerMock,
@@ -89,10 +99,8 @@ protected function setUp()
8999
*/
90100
public function testExecute()
91101
{
92-
$storeToSwitchToCode = 'sv2';
93-
$defaultStoreViewCode = 'default';
94-
$defaultStoreViewMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock();
95-
$storeToSwitchToMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
102+
$defaultStoreViewMock = $this->getMockBuilder(StoreInterface::class)->getMock();
103+
$storeToSwitchToMock = $this->getMockBuilder(StoreInterface::class)
96104
->disableOriginalConstructor()
97105
->setMethods(['isUseStoreInUrl'])
98106
->getMockForAbstractClass();
@@ -106,20 +114,20 @@ public function testExecute()
106114
->expects($this->once())
107115
->method('getById')
108116
->with(1)
109-
->willReturn($defaultStoreViewCode);
117+
->willReturn(self::STUB_DEFAULT_STORE_VIEW);
110118
$this->requestMock->expects($this->any())->method('getParam')->willReturnMap(
111119
[
112-
[StoreResolver::PARAM_NAME, null, $storeToSwitchToCode],
113-
['___from_store', null, $defaultStoreViewCode]
120+
[StoreResolver::PARAM_NAME, null, self::STUB_STORE_TO_SWITCH_TO_CODE],
121+
['___from_store', null, self::STUB_DEFAULT_STORE_VIEW]
114122
]
115123
);
116124
$this->storeRepositoryMock
117125
->expects($this->any())
118126
->method('get')
119127
->willReturnMap(
120128
[
121-
[$defaultStoreViewCode, $defaultStoreViewMock],
122-
[$storeToSwitchToCode, $storeToSwitchToMock]
129+
[self::STUB_DEFAULT_STORE_VIEW, $defaultStoreViewMock],
130+
[self::STUB_STORE_TO_SWITCH_TO_CODE, $storeToSwitchToMock]
123131
]
124132
);
125133

0 commit comments

Comments
 (0)