Skip to content

Commit 25b8622

Browse files
author
Alexander Paliarush
committed
MAGETWO-47377: Unnecessary StoreCookie plugin is executed on each request
1 parent 124f269 commit 25b8622

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class StoreCookieTest extends \PHPUnit_Framework_TestCase
3737
*/
3838
protected $storeMock;
3939

40-
/**
41-
* @var \Closure
42-
*/
43-
protected $closureMock;
44-
4540
/**
4641
* @var \Magento\Framework\App\FrontController|\PHPUnit_Framework_MockObject_MockObject
4742
*/
@@ -77,10 +72,6 @@ public function setUp()
7772
->setMethods([])
7873
->getMock();
7974

80-
$this->closureMock = function () {
81-
return 'ExpectedValue';
82-
};
83-
8475
$this->subjectMock = $this->getMockBuilder('Magento\Framework\App\FrontController')
8576
->disableOriginalConstructor()
8677
->setMethods([])
@@ -106,7 +97,7 @@ public function setUp()
10697
);
10798
}
10899

109-
public function testAroundDispatchNoSuchEntity()
100+
public function testBeforeDispatchNoSuchEntity()
110101
{
111102
$storeCode = 'store';
112103
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -115,13 +106,10 @@ public function testAroundDispatchNoSuchEntity()
115106
->method('getActiveStoreByCode')
116107
->willThrowException(new NoSuchEntityException);
117108
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
118-
$this->assertEquals(
119-
'ExpectedValue',
120-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
121-
);
109+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
122110
}
123111

124-
public function testAroundDispatchStoreIsInactive()
112+
public function testBeforeDispatchStoreIsInactive()
125113
{
126114
$storeCode = 'store';
127115
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -130,13 +118,10 @@ public function testAroundDispatchStoreIsInactive()
130118
->method('getActiveStoreByCode')
131119
->willThrowException(new StoreIsInactiveException);
132120
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
133-
$this->assertEquals(
134-
'ExpectedValue',
135-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
136-
);
121+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
137122
}
138123

139-
public function testAroundDispatchInvalidArgument()
124+
public function testBeforeDispatchInvalidArgument()
140125
{
141126
$storeCode = 'store';
142127
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -145,22 +130,16 @@ public function testAroundDispatchInvalidArgument()
145130
->method('getActiveStoreByCode')
146131
->willThrowException(new InvalidArgumentException);
147132
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
148-
$this->assertEquals(
149-
'ExpectedValue',
150-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
151-
);
133+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
152134
}
153135

154-
public function testAroundDispatchNoStoreCookie()
136+
public function testBeforeDispatchNoStoreCookie()
155137
{
156138
$storeCode = null;
157-
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
158139
$this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
140+
$this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock);
159141
$this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
160142
$this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
161-
$this->assertEquals(
162-
'ExpectedValue',
163-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
164-
);
143+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
165144
}
166145
}

0 commit comments

Comments
 (0)