Skip to content

Commit 54ae63a

Browse files
committed
Adjust Unit Tests for the change
1 parent 26aa6bd commit 54ae63a

File tree

1 file changed

+41
-49
lines changed

1 file changed

+41
-49
lines changed

app/code/Magento/Customer/Test/Unit/Controller/Plugin/AccountTest.php

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Customer\Test\Unit\Controller\Plugin;
78

9+
use Magento\Customer\Controller\AccountInterface;
810
use Magento\Customer\Controller\Plugin\Account;
911
use Magento\Customer\Model\Session;
1012
use Magento\Framework\App\ActionFlag;
1113
use Magento\Framework\App\ActionInterface;
12-
use Magento\Framework\App\Action\AbstractAction;
1314
use Magento\Framework\App\Request\Http;
15+
use Magento\Framework\App\Request\Http as HttpRequest;
1416
use Magento\Framework\Controller\ResultInterface;
1517
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
1620

17-
class AccountTest extends \PHPUnit\Framework\TestCase
21+
class AccountTest extends TestCase
1822
{
1923
/**
2024
* @var string
@@ -27,59 +31,51 @@ class AccountTest extends \PHPUnit\Framework\TestCase
2731
protected $plugin;
2832

2933
/**
30-
* @var Session | \PHPUnit_Framework_MockObject_MockObject
34+
* @var Session|MockObject
3135
*/
32-
protected $session;
36+
protected $sessionMock;
3337

3438
/**
35-
* @var AbstractAction | \PHPUnit_Framework_MockObject_MockObject
39+
* @var AccountInterface|MockObject
3640
*/
37-
protected $subject;
41+
protected $actionMock;
3842

3943
/**
40-
* @var Http | \PHPUnit_Framework_MockObject_MockObject
44+
* @var Http|MockObject
4145
*/
42-
protected $request;
46+
protected $requestMock;
4347

4448
/**
45-
* @var ActionFlag | \PHPUnit_Framework_MockObject_MockObject
49+
* @var ActionFlag|MockObject
4650
*/
47-
protected $actionFlag;
51+
protected $actionFlagMock;
4852

4953
/**
50-
* @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject
54+
* @var ResultInterface|MockObject
5155
*/
52-
private $resultInterface;
56+
private $resultMock;
5357

5458
protected function setUp()
5559
{
56-
$this->session = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
60+
$this->sessionMock = $this->getMockBuilder(Session::class)
5761
->disableOriginalConstructor()
58-
->setMethods([
59-
'setNoReferer',
60-
'unsNoReferer',
61-
'authenticate',
62-
])
62+
->setMethods(['setNoReferer', 'unsNoReferer', 'authenticate'])
6363
->getMock();
6464

65-
$this->subject = $this->getMockBuilder(AbstractAction::class)
66-
->setMethods([
67-
'getActionFlag',
68-
])
65+
$this->actionMock = $this->getMockBuilder(AccountInterface::class)
66+
->setMethods(['getActionFlag'])
6967
->disableOriginalConstructor()
7068
->getMockForAbstractClass();
7169

72-
$this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
70+
$this->requestMock = $this->getMockBuilder(HttpRequest::class)
7371
->disableOriginalConstructor()
74-
->setMethods([
75-
'getActionName',
76-
])
72+
->setMethods(['getActionName'])
7773
->getMock();
7874

79-
$this->resultInterface = $this->getMockBuilder(ResultInterface::class)
75+
$this->resultMock = $this->getMockBuilder(ResultInterface::class)
8076
->getMockForAbstractClass();
8177

82-
$this->actionFlag = $this->getMockBuilder(\Magento\Framework\App\ActionFlag::class)
78+
$this->actionFlagMock = $this->getMockBuilder(ActionFlag::class)
8379
->disableOriginalConstructor()
8480
->getMock();
8581
}
@@ -90,47 +86,43 @@ protected function setUp()
9086
* @param boolean $isActionAllowed
9187
* @param boolean $isAuthenticated
9288
*
93-
* @dataProvider beforeDispatchDataProvider
89+
* @dataProvider beforeExecuteDataProvider
9490
*/
95-
public function testBeforeDispatch(
96-
$action,
97-
$allowedActions,
98-
$isActionAllowed,
99-
$isAuthenticated
100-
) {
101-
$this->request->expects($this->once())
91+
public function testBeforeExecute($action, $allowedActions, $isActionAllowed, $isAuthenticated)
92+
{
93+
$this->requestMock->expects($this->once())
10294
->method('getActionName')
10395
->willReturn($action);
10496

10597
if ($isActionAllowed) {
106-
$this->session->expects($this->once())
98+
$this->sessionMock->expects($this->once())
10799
->method('setNoReferer')
108100
->with(true)
109101
->willReturnSelf();
110102
} else {
111-
$this->session->expects($this->once())
103+
$this->sessionMock->expects($this->once())
112104
->method('authenticate')
113105
->willReturn($isAuthenticated);
114106
if (!$isAuthenticated) {
115-
$this->subject->expects($this->once())
107+
$this->actionMock->expects($this->once())
116108
->method('getActionFlag')
117-
->willReturn($this->actionFlag);
109+
->willReturn($this->actionFlagMock);
118110

119-
$this->actionFlag->expects($this->once())
111+
$this->actionFlagMock->expects($this->once())
120112
->method('set')
121113
->with('', ActionInterface::FLAG_NO_DISPATCH, true)
122114
->willReturnSelf();
123115
}
124116
}
125117

126-
$plugin = new Account($this->session, $allowedActions);
127-
$plugin->beforeDispatch($this->subject, $this->request);
118+
$plugin = new Account($this->requestMock, $this->sessionMock, $allowedActions);
119+
$plugin->beforeExecute($this->actionMock);
128120
}
129121

130122
/**
131123
* @return array
132124
*/
133-
public function beforeDispatchDataProvider()
125+
public function beforeExecuteDataProvider()
134126
{
135127
return [
136128
[
@@ -166,23 +158,23 @@ public function beforeDispatchDataProvider()
166158
];
167159
}
168160

169-
public function testAfterDispatch()
161+
public function testAfterExecute()
170162
{
171-
$this->session->expects($this->once())
163+
$this->sessionMock->expects($this->once())
172164
->method('unsNoReferer')
173165
->with(false)
174166
->willReturnSelf();
175167

176168
$plugin = (new ObjectManager($this))->getObject(
177169
Account::class,
178170
[
179-
'session' => $this->session,
171+
'session' => $this->sessionMock,
180172
'allowedActions' => ['testaction']
181173
]
182174
);
183175
$this->assertSame(
184-
$this->resultInterface,
185-
$plugin->afterDispatch($this->subject, $this->resultInterface, $this->request)
176+
$this->resultMock,
177+
$plugin->afterExecute($this->actionMock, $this->resultMock, $this->requestMock)
186178
);
187179
}
188180
}

0 commit comments

Comments
 (0)