37 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40 $this->model =
$helper->getObject(
41 \
Magento\SalesRule\Observer\SalesOrderAfterPlaceObserver::class,
43 'ruleFactory' => $this->ruleFactory,
44 'ruleCustomerFactory' => $this->ruleCustomerFactory,
45 'coupon' => $this->couponMock,
46 'couponUsage' => $this->couponUsage,
53 $this->couponMock = $this->createPartialMock(\
Magento\SalesRule\Model\Coupon::class, [
62 'updateCustomerCouponTimesUsed' 64 $this->ruleFactory = $this->createPartialMock(\
Magento\SalesRule\Model\RuleFactory::class, [
'create']);
65 $this->ruleCustomerFactory = $this->createPartialMock(
66 \
Magento\SalesRule\Model\Rule\CustomerFactory::class,
69 $this->couponUsage = $this->createMock(\
Magento\SalesRule\Model\
ResourceModel\Coupon\Usage::class);
78 $event = $this->createPartialMock(\
Magento\Framework\Event::class, [
'getOrder']);
79 $order = $this->createPartialMock(
80 \
Magento\Sales\Model\Order::class,
81 [
'getAppliedRuleIds',
'getCustomerId',
'getDiscountAmount',
'getCouponCode',
'__wakeup']
86 ->will($this->returnValue($event));
87 $event->expects($this->any())
89 ->will($this->returnValue(
$order));
99 $this->assertEquals($this->model, $this->model->execute(
$observer));
107 $order->expects($this->once())
108 ->method(
'getAppliedRuleIds')
109 ->will($this->returnValue($ruleIds));
111 $this->ruleFactory->expects($this->never())
113 $this->assertEquals($this->model, $this->model->execute(
$observer));
123 $rule = $this->createMock(\
Magento\SalesRule\Model\Rule::class);
124 $ruleCustomer = $this->createPartialMock(\
Magento\SalesRule\Model\Rule\Customer::class, [
126 'loadByCustomerRule',
138 $order->expects($this->exactly(2))
139 ->method(
'getAppliedRuleIds')
140 ->will($this->returnValue(
$ruleId));
141 $order->expects($this->once())
142 ->method(
'getCustomerId')
144 $this->ruleFactory->expects($this->once())
146 ->will($this->returnValue(
$rule));
147 $rule->expects($this->once())
149 ->will($this->returnValue(
$ruleId));
150 $this->ruleCustomerFactory->expects($this->once())
152 ->will($this->returnValue($ruleCustomer));
153 $ruleCustomer->expects($this->once())
155 ->will($this->returnValue($ruleCustomerId));
156 $ruleCustomer->expects($this->any())
157 ->method(
'setCustomerId')
158 ->will($this->returnSelf());
159 $ruleCustomer->expects($this->any())
160 ->method(
'setRuleId')
161 ->will($this->returnSelf());
162 $this->couponMock->expects($this->any())
164 ->will($this->returnValue($couponId));
166 $this->couponUsage->expects($this->once())
167 ->method(
'updateCustomerCouponTimesUsed')
170 $this->assertEquals($this->model, $this->model->execute(
$observer));
179 'With customer rule id' => [1],
180 'Without customer rule id' => [
null]
salesOrderAfterPlaceDataProvider()
testSalesOrderAfterPlace($ruleCustomerId)
testSalesOrderAfterPlaceWithoutRuleId()
initOrderFromEvent($observer)
testSalesOrderAfterPlaceWithoutOrder()