27 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
30 $this->model =
$helper->getObject(
31 \
Magento\SalesRule\Observer\AddSalesRuleNameToOrderObserver::class,
33 'ruleFactory' => $this->ruleFactory,
34 'coupon' => $this->couponMock,
41 $this->couponMock = $this->createPartialMock(\
Magento\SalesRule\Model\Coupon::class, [
50 'updateCustomerCouponTimesUsed' 52 $this->ruleFactory = $this->createPartialMock(\
Magento\SalesRule\Model\RuleFactory::class, [
'create']);
57 $observer = $this->createPartialMock(\
Magento\Framework\Event\Observer::class, [
'getOrder']);
58 $order = $this->createPartialMock(
59 \
Magento\Sales\Model\Order::class,
60 [
'setCouponRuleName',
'getCouponCode',
'__wakeup']
65 ->will($this->returnValue(
$order));
67 $this->couponMock->expects($this->never())
68 ->method(
'loadByCode');
70 $this->assertEquals($this->model, $this->model->execute(
$observer));
75 $observer = $this->createPartialMock(\
Magento\Framework\Event\Observer::class, [
'getOrder']);
76 $order = $this->createPartialMock(
77 \
Magento\Sales\Model\Order::class,
78 [
'setCouponRuleName',
'getCouponCode',
'__wakeup']
84 ->will($this->returnValue(
$order));
86 $order->expects($this->once())
87 ->method(
'getCouponCode')
89 $this->ruleFactory->expects($this->never())
92 $this->assertEquals($this->model, $this->model->execute(
$observer));
97 $observer = $this->createPartialMock(\
Magento\Framework\Event\Observer::class, [
'getOrder']);
98 $rule = $this->createPartialMock(\
Magento\SalesRule\Model\Rule::class, [
'load',
'getName',
'__wakeup']);
99 $order = $this->createPartialMock(
100 \
Magento\Sales\Model\Order::class,
101 [
'setCouponRuleName',
'getCouponCode',
'__wakeup']
108 ->will($this->returnValue(
$order));
110 $order->expects($this->once())
111 ->method(
'getCouponCode')
113 $this->couponMock->expects($this->once())
114 ->method(
'getRuleId')
115 ->will($this->returnValue(
$ruleId));
116 $this->ruleFactory->expects($this->once())
118 ->will($this->returnValue(
$rule));
119 $rule->expects($this->once())
122 ->will($this->returnSelf());
123 $order->expects($this->once())
124 ->method(
'setCouponRuleName');
126 $this->assertEquals($this->model, $this->model->execute(
$observer));
testAddSalesRuleNameToOrderWithoutRule()
testAddSalesRuleNameToOrder()
testAddSalesRuleNameToOrderWithoutCouponCode()