5
5
*/
6
6
namespace Magento \Customer \Test \Unit \Model \Plugin ;
7
7
8
- use Magento \Backend \App \AbstractAction ;
9
8
use Magento \Customer \Api \CustomerRepositoryInterface ;
10
9
use Magento \Customer \Api \Data \CustomerInterface ;
11
10
use Magento \Customer \Model \Customer \NotificationStorage ;
12
11
use Magento \Customer \Model \Plugin \CustomerNotification ;
13
12
use Magento \Customer \Model \Session ;
13
+ use Magento \Framework \App \ActionInterface ;
14
14
use Magento \Framework \App \Area ;
15
15
use Magento \Framework \App \RequestInterface ;
16
16
use Magento \Framework \App \State ;
20
20
class CustomerNotificationTest extends \PHPUnit \Framework \TestCase
21
21
{
22
22
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */
23
- private $ sessionMock ;
23
+ private $ session ;
24
24
25
25
/** @var NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
26
- private $ notificationStorageMock ;
26
+ private $ notificationStorage ;
27
27
28
28
/** @var CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
29
- private $ customerRepositoryMock ;
29
+ private $ customerRepository ;
30
30
31
31
/** @var State|\PHPUnit_Framework_MockObject_MockObject */
32
- private $ appStateMock ;
32
+ private $ appState ;
33
33
34
34
/** @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
35
- private $ requestMock ;
35
+ private $ request ;
36
36
37
- /** @var AbstractAction |\PHPUnit_Framework_MockObject_MockObject */
38
- private $ abstractActionMock ;
39
-
40
- /** @var LoggerInterface */
41
- private $ loggerMock ;
37
+ /** @var ActionInterface |\PHPUnit_Framework_MockObject_MockObject */
38
+ private $ actionInterfaceMock ;
39
+
40
+ /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
41
+ private $ logger ;
42
42
43
43
/** @var CustomerNotification */
44
44
private $ plugin ;
@@ -48,76 +48,61 @@ class CustomerNotificationTest extends \PHPUnit\Framework\TestCase
48
48
49
49
protected function setUp ()
50
50
{
51
- $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
52
- ->disableOriginalConstructor ()
53
- ->setMethods (['getCustomerId ' , 'setCustomerData ' , 'setCustomerGroupId ' , 'regenerateId ' ])
54
- ->getMock ();
55
- $ this ->notificationStorageMock = $ this ->getMockBuilder (NotificationStorage::class)
56
- ->disableOriginalConstructor ()
57
- ->setMethods (['isExists ' , 'remove ' ])
58
- ->getMock ();
59
- $ this ->customerRepositoryMock = $ this ->getMockBuilder (CustomerRepositoryInterface::class)
60
- ->getMockForAbstractClass ();
61
- $ this ->abstractActionMock = $ this ->getMockBuilder (AbstractAction::class)
62
- ->disableOriginalConstructor ()
63
- ->getMockForAbstractClass ();
64
- $ this ->requestMock = $ this ->getMockBuilder (RequestInterface::class)
51
+ $ this ->session = $ this ->createMock (Session::class);
52
+ $ this ->notificationStorage = $ this ->createMock (NotificationStorage::class);
53
+ $ this ->customerRepository = $ this ->createMock (CustomerRepositoryInterface::class);
54
+ $ this ->actionInterfaceMock = $ this ->createMock (ActionInterface::class);
55
+ $ this ->request = $ this ->getMockBuilder (RequestInterface::class)
65
56
->setMethods (['isPost ' ])
66
57
->getMockForAbstractClass ();
67
- $ this ->appStateMock = $ this ->getMockBuilder (State::class)
68
- ->disableOriginalConstructor ()
69
- ->setMethods (['getAreaCode ' ])
70
- ->getMock ();
71
-
72
- $ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
73
- $ this ->appStateMock ->method ('getAreaCode ' )->willReturn (Area::AREA_FRONTEND );
74
- $ this ->requestMock ->method ('isPost ' )->willReturn (true );
75
- $ this ->sessionMock ->method ('getCustomerId ' )->willReturn (self ::$ customerId );
76
- $ this ->notificationStorageMock ->expects ($ this ->any ())
58
+ $ this ->appState = $ this ->createMock (State::class);
59
+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
60
+
61
+ $ this ->appState ->method ('getAreaCode ' )->willReturn (Area::AREA_FRONTEND );
62
+ $ this ->request ->method ('isPost ' )->willReturn (true );
63
+ $ this ->session ->method ('getCustomerId ' )->willReturn (self ::$ customerId );
64
+ $ this ->notificationStorage ->expects ($ this ->any ())
77
65
->method ('isExists ' )
78
66
->with (NotificationStorage::UPDATE_CUSTOMER_SESSION , self ::$ customerId )
79
67
->willReturn (true );
80
68
81
69
$ this ->plugin = new CustomerNotification (
82
- $ this ->sessionMock ,
83
- $ this ->notificationStorageMock ,
84
- $ this ->appStateMock ,
85
- $ this ->customerRepositoryMock ,
86
- $ this ->loggerMock
70
+ $ this ->session ,
71
+ $ this ->notificationStorage ,
72
+ $ this ->appState ,
73
+ $ this ->customerRepository ,
74
+ $ this ->logger ,
75
+ $ this ->request
87
76
);
88
77
}
89
78
90
- public function testBeforeDispatch ()
79
+ public function testBeforeExecute ()
91
80
{
92
81
$ customerGroupId =1 ;
93
82
94
- $ customerMock = $ this ->getMockForAbstractClass (CustomerInterface::class);
83
+ $ customerMock = $ this ->createMock (CustomerInterface::class);
95
84
$ customerMock ->method ('getGroupId ' )->willReturn ($ customerGroupId );
96
85
$ customerMock ->method ('getId ' )->willReturn (self ::$ customerId );
97
86
98
- $ this ->customerRepositoryMock ->expects ($ this ->once ())
87
+ $ this ->customerRepository ->expects ($ this ->once ())
99
88
->method ('getById ' )
100
89
->with (self ::$ customerId )
101
90
->willReturn ($ customerMock );
102
- $ this ->notificationStorageMock ->expects ($ this ->once ())
91
+ $ this ->notificationStorage ->expects ($ this ->once ())
103
92
->method ('remove ' )
104
93
->with (NotificationStorage::UPDATE_CUSTOMER_SESSION , self ::$ customerId );
105
94
106
- $ this ->sessionMock ->expects ($ this ->once ())->method ('setCustomerData ' )->with ($ customerMock );
107
- $ this ->sessionMock ->expects ($ this ->once ())->method ('setCustomerGroupId ' )->with ($ customerGroupId );
108
- $ this ->sessionMock ->expects ($ this ->once ())->method ('regenerateId ' );
109
-
110
- $ this ->plugin ->beforeDispatch ($ this ->abstractActionMock , $ this ->requestMock );
95
+ $ this ->plugin ->beforeExecute ($ this ->actionInterfaceMock );
111
96
}
112
97
113
98
public function testBeforeDispatchWithNoCustomerFound ()
114
99
{
115
- $ this ->customerRepositoryMock ->method ('getById ' )
100
+ $ this ->customerRepository ->method ('getById ' )
116
101
->with (self ::$ customerId )
117
102
->willThrowException (new NoSuchEntityException ());
118
- $ this ->loggerMock ->expects ($ this ->once ())
103
+ $ this ->logger ->expects ($ this ->once ())
119
104
->method ('error ' );
120
105
121
- $ this ->plugin ->beforeDispatch ($ this ->abstractActionMock , $ this -> requestMock );
106
+ $ this ->plugin ->beforeExecute ($ this ->actionInterfaceMock );
122
107
}
123
108
}
0 commit comments