@@ -57,7 +57,7 @@ protected function setUp()
57
57
->getMock ();
58
58
$ this ->eventMock = $ this ->getMockBuilder ('Magento\Framework\Event ' )
59
59
->disableOriginalConstructor ()
60
- ->setMethods (['getOrigCustomerDataObject ' , ' getCustomerDataObject ' ])
60
+ ->setMethods (['getCustomerDataObject ' ])
61
61
->getMock ();
62
62
$ this ->observerMock ->expects ($ this ->any ())->method ('getEvent ' )->will ($ this ->returnValue ($ this ->eventMock ));
63
63
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -91,8 +91,9 @@ public function testDispatchNoCustomerGroupChange()
91
91
$ this ->eventMock ->expects ($ this ->any ())
92
92
->method ('getOrigCustomerDataObject ' )
93
93
->will ($ this ->returnValue ($ origCustomerDataObjectMock ));
94
- $ this ->quoteRepositoryMock ->expects ($ this ->never ())
95
- ->method ('getForCustomer ' );
94
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
95
+ ->method ('getForCustomer ' )
96
+ ->willThrowException (new \Magento \Framework \Exception \NoSuchEntityException ());
96
97
97
98
$ this ->customerQuote ->dispatch ($ this ->observerMock );
98
99
}
@@ -128,57 +129,38 @@ public function testDispatch($isWebsiteScope, $websites, $quoteId)
128
129
->method ('getWebsites ' )
129
130
->will ($ this ->returnValue ($ websites ));
130
131
}
131
- $ origCustomerDataObjectMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )
132
- ->disableOriginalConstructor ()
133
- ->getMock ();
134
- $ origCustomerDataObjectMock ->expects ($ this ->any ())
135
- ->method ('getGroupId ' )
136
- ->will ($ this ->returnValue (2 ));
137
132
$ this ->eventMock ->expects ($ this ->any ())
138
133
->method ('getCustomerDataObject ' )
139
134
->will ($ this ->returnValue ($ customerDataObjectMock ));
140
- $ this ->eventMock ->expects ($ this ->any ())
141
- ->method ('getOrigCustomerDataObject ' )
142
- ->will ($ this ->returnValue ($ origCustomerDataObjectMock ));
143
135
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote $quoteMock */
144
136
$ quoteMock = $ this ->getMockBuilder (
145
137
'Magento\Quote\Model\Quote '
146
138
)->setMethods (
147
139
[
148
140
'setWebsite ' ,
149
141
'setCustomerGroupId ' ,
142
+ 'getCustomerGroupId ' ,
150
143
'collectTotals ' ,
151
144
'__wakeup ' ,
152
145
]
153
146
)->disableOriginalConstructor (
154
147
)->getMock ();
155
148
$ websiteCount = count ($ websites );
156
- if ($ quoteId ) {
157
- $ this ->quoteRepositoryMock ->expects ($ this ->exactly ($ websiteCount ))
158
- ->method ('getForCustomer ' )
159
- ->will ($ this ->returnValue ($ quoteMock ));
160
- $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
161
- ->method ('setWebsite ' );
162
- $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
163
- ->method ('setCustomerGroupId ' );
164
- $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
165
- ->method ('collectTotals ' );
166
- $ this ->quoteRepositoryMock ->expects ($ this ->exactly ($ websiteCount ))
167
- ->method ('save ' )
168
- ->with ($ quoteMock );
169
- } else {
170
- $ this ->quoteRepositoryMock ->expects ($ this ->exactly ($ websiteCount ))
171
- ->method ('getForCustomer ' )
172
- ->willThrowException (
173
- new \Magento \Framework \Exception \NoSuchEntityException ()
174
- );
175
- $ quoteMock ->expects ($ this ->never ())
176
- ->method ('setCustomerGroupId ' );
177
- $ quoteMock ->expects ($ this ->never ())
178
- ->method ('collectTotals ' );
179
- $ this ->quoteRepositoryMock ->expects ($ this ->never ())
180
- ->method ('save ' );
181
- }
149
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
150
+ ->method ('getForCustomer ' )
151
+ ->will ($ this ->returnValue ($ quoteMock ));
152
+ $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
153
+ ->method ('setWebsite ' );
154
+ $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
155
+ ->method ('setCustomerGroupId ' );
156
+ $ quoteMock ->expects ($ this ->exactly ($ websiteCount ))
157
+ ->method ('collectTotals ' );
158
+ $ this ->quoteRepositoryMock ->expects ($ this ->exactly ($ websiteCount ))
159
+ ->method ('save ' )
160
+ ->with ($ quoteMock );
161
+ $ quoteMock ->expects ($ this ->once ())
162
+ ->method ('getCustomerGroupId ' )
163
+ ->willReturn (2 );
182
164
$ this ->customerQuote ->dispatch ($ this ->observerMock );
183
165
}
184
166
0 commit comments