Skip to content

Commit 8bfa512

Browse files
MAGETWO-39857: Event 'customer_save_after_data_object' dispatches a few times
1 parent 765999d commit 8bfa512

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

app/code/Magento/Quote/Test/Unit/Model/Observer/Backend/CustomerQuoteTest.php

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUp()
5757
->getMock();
5858
$this->eventMock = $this->getMockBuilder('Magento\Framework\Event')
5959
->disableOriginalConstructor()
60-
->setMethods(['getOrigCustomerDataObject', 'getCustomerDataObject'])
60+
->setMethods(['getCustomerDataObject'])
6161
->getMock();
6262
$this->observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->eventMock));
6363
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -91,8 +91,9 @@ public function testDispatchNoCustomerGroupChange()
9191
$this->eventMock->expects($this->any())
9292
->method('getOrigCustomerDataObject')
9393
->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());
9697

9798
$this->customerQuote->dispatch($this->observerMock);
9899
}
@@ -128,57 +129,38 @@ public function testDispatch($isWebsiteScope, $websites, $quoteId)
128129
->method('getWebsites')
129130
->will($this->returnValue($websites));
130131
}
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));
137132
$this->eventMock->expects($this->any())
138133
->method('getCustomerDataObject')
139134
->will($this->returnValue($customerDataObjectMock));
140-
$this->eventMock->expects($this->any())
141-
->method('getOrigCustomerDataObject')
142-
->will($this->returnValue($origCustomerDataObjectMock));
143135
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote $quoteMock */
144136
$quoteMock = $this->getMockBuilder(
145137
'Magento\Quote\Model\Quote'
146138
)->setMethods(
147139
[
148140
'setWebsite',
149141
'setCustomerGroupId',
142+
'getCustomerGroupId',
150143
'collectTotals',
151144
'__wakeup',
152145
]
153146
)->disableOriginalConstructor(
154147
)->getMock();
155148
$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);
182164
$this->customerQuote->dispatch($this->observerMock);
183165
}
184166

0 commit comments

Comments
 (0)