Skip to content

Commit 10fbf40

Browse files
committed
Static test improvement.
1 parent 11480e8 commit 10fbf40

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

app/code/Magento/Sales/Model/Order/CustomerAssignment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function execute(OrderInterface $order, CustomerInterface $customer)/*: v
4949
$this->orderRepository->save($order);
5050

5151
$this->eventManager->dispatch(
52-
'sales_order_customer_assign_after', [
52+
'sales_order_customer_assign_after',
53+
[
5354
'order' => $order,
5455
'customer' => $customer
5556
]

app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AssignOrderToCustomerObserverTest extends TestCase
2929
protected $orderRepositoryMock;
3030

3131
/** @var CustomerAssignment | PHPUnit_Framework_MockObject_MockObject */
32-
protected $customerAssignmentMock;
32+
protected $assignmentMock;
3333

3434
/**
3535
* Set Up
@@ -40,11 +40,11 @@ protected function setUp()
4040
->disableOriginalConstructor()
4141
->getMock();
4242

43-
$this->customerAssignmentMock = $this->getMockBuilder(CustomerAssignment::class)
43+
$this->assignmentMock = $this->getMockBuilder(CustomerAssignment::class)
4444
->disableOriginalConstructor()
4545
->getMock();
4646

47-
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->customerAssignmentMock);
47+
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->assignmentMock);
4848
}
4949

5050
/**
@@ -78,12 +78,14 @@ public function testAssignOrderToCustomerAfterGuestOrder($customerId)
7878
$orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
7979
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)
8080
->willReturn($orderMock);
81+
8182
if ($customerId) {
82-
$this->customerAssignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock);
83-
} else {
84-
$this->customerAssignmentMock->expects($this->never())->method('execute');
83+
$this->assignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock);
84+
$this->sut->execute($observerMock);
85+
return;
8586
}
8687

88+
$this->assignmentMock->expects($this->never())->method('execute');
8789
$this->sut->execute($observerMock);
8890
}
8991

dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
use Magento\Sales\Model\Order;
3+
namespace Magento\SalesRule\Model\Observer;
44

5+
use Magento\Sales\Model\Order;
56
use Magento\Customer\Model\GroupManagement;
67
use Magento\SalesRule\Api\CouponRepositoryInterface;
78
use Magento\SalesRule\Model\Coupon;
@@ -13,6 +14,8 @@
1314
/**
1415
* Class AssignCouponDataAfterOrderCustomerAssignTest
1516
*
17+
* @magentoAppIsolation enabled
18+
*
1619
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1720
*/
1821
class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\TestCase
@@ -80,12 +83,12 @@ public function __construct($name = null, array $data = [], $dataName = '')
8083
parent::__construct($name, $data, $dataName);
8184
$this->objectManager = Bootstrap::getObjectManager();
8285
$this->eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
83-
$this->orderRepository = $this->objectManager->get(Magento\Sales\Model\OrderRepository::class);
86+
$this->orderRepository = $this->objectManager->get(\Magento\Sales\Model\OrderRepository::class);
8487
$this->delegateCustomerService = $this->objectManager->get(Order\OrderCustomerDelegate::class);
8588
$this->customerRepository = $this->objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
86-
$this->ruleCustomerFactory = $this->objectManager->get(Magento\SalesRule\Model\Rule\CustomerFactory::class);;
89+
$this->ruleCustomerFactory = $this->objectManager->get(\Magento\SalesRule\Model\Rule\CustomerFactory::class);
8790
$this->assignCouponToCustomerObserver = $this->objectManager->get(
88-
Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class
91+
\Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class
8992
);
9093
}
9194

@@ -116,7 +119,6 @@ protected function tearDown()
116119
}
117120

118121
/**
119-
* @magentoAppIsolation enabled
120122
* @magentoDataFixture Magento/Sales/_files/order.php
121123
*/
122124
public function testCouponDataHasBeenAssignedTest()
@@ -137,15 +139,14 @@ public function testCouponDataHasBeenAssignedTest()
137139
}
138140

139141
/**
140-
* @magentoAppIsolation enabled
141142
* @magentoDataFixture Magento/Sales/_files/order.php
142143
*/
143144
public function testOrderCancelingDecreasesCouponUsages()
144145
{
145146
$this->processOrder($this->order);
146147

147148
// Should not throw exception as bux is fixed now
148-
$this->cancelOrder($this->order);
149+
$this->order->cancel();
149150
$ruleCustomer = $this->getSalesruleCustomerUsage($this->customer, $this->salesRule);
150151

151152
// Assert, that rule customer model has been created for specific customer
@@ -172,20 +173,12 @@ private function processOrder(Order $order)
172173
return $this->orderRepository->save($order);
173174
}
174175

175-
/**
176-
* @param Order $order
177-
*/
178-
private function cancelOrder(Order $order)
179-
{
180-
$order->cancel();
181-
}
182-
183176
/**
184177
* @param Customer $customer
185178
* @param Rule $rule
186179
* @return Rule\Customer
187180
*/
188-
private function getSalesruleCustomerUsage(Customer $customer, Rule $rule) : Magento\SalesRule\Model\Rule\Customer
181+
private function getSalesruleCustomerUsage(Customer $customer, Rule $rule) : \Magento\SalesRule\Model\Rule\Customer
189182
{
190183
$ruleCustomer = $this->ruleCustomerFactory->create();
191184
return $ruleCustomer->loadByCustomerRule($customer->getId(), $rule->getRuleId());
@@ -301,4 +294,3 @@ private function registerNewCustomer() : Customer
301294
return $customer;
302295
}
303296
}
304-

0 commit comments

Comments
 (0)