/** * @param int|bool $ruleCustomerId * @dataProvider salesOrderAfterPlaceDataProvider */ public function testSalesOrderAfterPlace($ruleCustomerId) { $observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $rule = $this->getMock('Magento\\SalesRule\\Model\\Rule', [], [], '', false); $ruleCustomer = $this->getMock('Magento\\SalesRule\\Model\\Rule\\Customer', ['setCustomerId', 'loadByCustomerRule', 'getId', 'setTimesUsed', 'setRuleId', 'save', '__wakeup'], [], '', false); $order = $this->initOrderFromEvent($observer); $ruleId = 1; $couponId = 1; $customerId = 1; $discountAmount = 10; $order->expects($this->once())->method('getAppliedRuleIds')->will($this->returnValue($ruleId)); $order->expects($this->once())->method('getDiscountAmount')->will($this->returnValue($discountAmount)); $order->expects($this->once())->method('getCustomerId')->will($this->returnValue($customerId)); $this->ruleFactory->expects($this->once())->method('create')->will($this->returnValue($rule)); $rule->expects($this->once())->method('getId')->will($this->returnValue($ruleId)); $this->ruleCustomerFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCustomer)); $ruleCustomer->expects($this->once())->method('getId')->will($this->returnValue($ruleCustomerId)); $ruleCustomer->expects($this->any())->method('setCustomerId')->will($this->returnSelf()); $ruleCustomer->expects($this->any())->method('setRuleId')->will($this->returnSelf()); $this->couponMock->expects($this->any())->method('getId')->will($this->returnValue($couponId)); $this->couponUsage->expects($this->once())->method('updateCustomerCouponTimesUsed')->with($customerId, $couponId); $this->assertEquals($this->model, $this->model->salesOrderAfterPlace($observer)); }