From cede04f014733bffc5104f2e26579e8ce242f462 Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Tue, 27 Nov 2018 18:33:00 +0200 Subject: [PATCH 01/15] Fixed bug, when exception occurred on order with coupons cancel, made by guest after creating of customer account. --- .../Sales/Model/Order/CustomerAssignment.php | 58 ++++ .../AssignOrderToCustomerObserver.php | 23 +- ...onDataAfterOrderCustomerAssignObserver.php | 52 ++++ app/code/Magento/SalesRule/etc/events.xml | 3 + ...CouponDataAfterOrderCustomerAssignTest.php | 269 ++++++++++++++++++ 5 files changed, 398 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/Sales/Model/Order/CustomerAssignment.php create mode 100644 app/code/Magento/SalesRule/Observer/AssignCouponDataAfterOrderCustomerAssignObserver.php create mode 100644 dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php diff --git a/app/code/Magento/Sales/Model/Order/CustomerAssignment.php b/app/code/Magento/Sales/Model/Order/CustomerAssignment.php new file mode 100644 index 0000000000000..b6ae86461c398 --- /dev/null +++ b/app/code/Magento/Sales/Model/Order/CustomerAssignment.php @@ -0,0 +1,58 @@ +eventManager = $eventManager; + $this->orderRepository = $orderRepository; + } + + /** + * @param OrderInterface $order + * @param CustomerInterface $customer + */ + public function execute(OrderInterface $order, CustomerInterface $customer)/*: void*/ + { + $order->setCustomerId($customer->getId()); + $order->setCustomerIsGuest(false); + $this->orderRepository->save($order); + + $this->eventManager->dispatch( + 'sales_order_customer_assign_after', [ + 'order' => $order, + 'customer' => $customer + ] + ); + } +} diff --git a/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php b/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php index f41ea6888264f..aba7d551d5330 100644 --- a/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php +++ b/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php @@ -12,6 +12,7 @@ use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\Order\CustomerAssignment; /** * Assign order to customer created after issuing guest order. @@ -24,11 +25,22 @@ class AssignOrderToCustomerObserver implements ObserverInterface private $orderRepository; /** + * @var CustomerAssignment + */ + private $customerAssignmentService; + + /** + * AssignOrderToCustomerObserver constructor. + * * @param OrderRepositoryInterface $orderRepository + * @param CustomerAssignment $customerAssignmentService */ - public function __construct(OrderRepositoryInterface $orderRepository) - { + public function __construct( + OrderRepositoryInterface $orderRepository, + CustomerAssignment $customerAssignmentService + ) { $this->orderRepository = $orderRepository; + $this->customerAssignmentService = $customerAssignmentService; } /** @@ -44,11 +56,8 @@ public function execute(Observer $observer) if (array_key_exists('__sales_assign_order_id', $delegateData)) { $orderId = $delegateData['__sales_assign_order_id']; $order = $this->orderRepository->get($orderId); - if (!$order->getCustomerId()) { - //if customer ID wasn't already assigned then assigning. - $order->setCustomerId($customer->getId()); - $order->setCustomerIsGuest(0); - $this->orderRepository->save($order); + if (!$order->getCustomerId() && $customer->getId()) { + $this->customerAssignmentService->execute($order, $customer); } } } diff --git a/app/code/Magento/SalesRule/Observer/AssignCouponDataAfterOrderCustomerAssignObserver.php b/app/code/Magento/SalesRule/Observer/AssignCouponDataAfterOrderCustomerAssignObserver.php new file mode 100644 index 0000000000000..d9699d334ff6a --- /dev/null +++ b/app/code/Magento/SalesRule/Observer/AssignCouponDataAfterOrderCustomerAssignObserver.php @@ -0,0 +1,52 @@ +updateCouponUsages = $updateCouponUsages; + } + + /** + * @inheritDoc + */ + public function execute(Observer $observer) + { + $event = $observer->getEvent(); + /** @var OrderInterface $order */ + $order = $event->getData(self::EVENT_KEY_ORDER); + + if ($order->getCustomerId()) { + $this->updateCouponUsages->execute($order, true); + } + } +} diff --git a/app/code/Magento/SalesRule/etc/events.xml b/app/code/Magento/SalesRule/etc/events.xml index 8261860bbb7ce..eec0da74f619e 100644 --- a/app/code/Magento/SalesRule/etc/events.xml +++ b/app/code/Magento/SalesRule/etc/events.xml @@ -24,4 +24,7 @@ + + + diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php new file mode 100644 index 0000000000000..d04423daabdf9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -0,0 +1,269 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); + $this->orderRepository = $this->objectManager->get(Magento\Sales\Model\OrderRepository::class); + $this->delegateCustomerService = $this->objectManager->get(Order\OrderCustomerDelegate::class); + $this->customerRepository = $this->objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class); + $this->ruleCustomerFactory = $this->objectManager->get(Magento\SalesRule\Model\Rule\CustomerFactory::class);; + $this->assignCouponToCustomerObserver = $this->objectManager->get( + Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class + ); + } + + /** + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Sales/_files/order.php + */ + public function testCouponDataHasBeenAssignedTest() + { + $rule = $this->prepareSalesRule(); + $coupon = $this->attachSalesruleCoupon($rule); + + $order = $this->makeOrderWithCouponAsGuest($coupon); + $this->delegateOrderToBeAssigned($order); + + $customer = $this->registerNewCustomer(); + $ruleCustomer = $this->getSalesruleCustomerUsage($customer, $rule); + + // Assert, that rule customer model has been created for specific customer + $this->assertEquals( + $ruleCustomer->getCustomerId(), + $customer->getId() + ); + + // Assert, that customer has increased coupon usage of specific rule + $this->assertEquals( + 1, + $ruleCustomer->getTimesUsed() + ); + } + + /** + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Sales/_files/order.php + */ + public function testOrderCancelingDecreasesCouponUsages() + { + $rule = $this->prepareSalesRule(); + $coupon = $this->attachSalesruleCoupon($rule); + + $order = $this->makeOrderWithCouponAsGuest($coupon); + $this->delegateOrderToBeAssigned($order); + + $customer = $this->registerNewCustomer(); + + $order->setCustomerId($customer->getId()); + $this->processOrder($order); + + // Should not throw exception as bux is fixed now + $this->cancelOrder($order); + $ruleCustomer = $this->getSalesruleCustomerUsage($customer, $rule); + + // Assert, that rule customer model has been created for specific customer + $this->assertEquals( + $ruleCustomer->getCustomerId(), + $customer->getId() + ); + + // Assert, that customer has increased coupon usage of specific rule + $this->assertEquals( + 0, + $ruleCustomer->getTimesUsed() + ); + + } + + /** + * @param Order $order + * @return \Magento\Sales\Api\Data\OrderInterface + */ + private function processOrder(Order $order) + { + $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING); + $order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING); + return $this->orderRepository->save($order); + } + + /** + * @param Order $order + */ + private function cancelOrder(Order $order) + { + $order->cancel(); + } + + /** + * @param Customer $customer + * @param Rule $rule + * @return Rule\Customer + */ + private function getSalesruleCustomerUsage(Customer $customer, Rule $rule) : Magento\SalesRule\Model\Rule\Customer + { + $ruleCustomer = $this->ruleCustomerFactory->create(); + return $ruleCustomer->loadByCustomerRule($customer->getId(), $rule->getRuleId()); + } + + /** + * @return Rule + */ + private function prepareSalesRule() : Rule + { + /** @var Rule $salesRule */ + $salesRule = $this->objectManager->create(Rule::class); + $salesRule->setData( + [ + 'name' => '15$ fixed discount on whole cart', + 'is_active' => 1, + 'customer_group_ids' => [GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => Rule::COUPON_TYPE_SPECIFIC, + 'conditions' => [ + [ + 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class, + 'attribute' => 'base_subtotal', + 'operator' => '>', + 'value' => 45, + ], + ], + 'simple_action' => Rule::CART_FIXED_ACTION, + 'discount_amount' => 15, + 'discount_step' => 0, + 'stop_rules_processing' => 1, + 'website_ids' => [ + $this->objectManager->get(StoreManagerInterface::class)->getWebsite()->getId(), + ], + ] + ); + $this->objectManager->get( + \Magento\SalesRule\Model\ResourceModel\Rule::class + )->save($salesRule); + + return $salesRule; + } + + /** + * @param Rule $salesRule + * @return Coupon + */ + private function attachSalesruleCoupon(Rule $salesRule) : Coupon + { + $coupon = $this->objectManager->create(Coupon::class); + $coupon->setRuleId($salesRule->getId()) + ->setCode('CART_FIXED_DISCOUNT_15') + ->setType(0); + + $this->objectManager->get(CouponRepositoryInterface::class)->save($coupon); + + return $coupon; + } + + /** + * @param Coupon $coupon + * @return Order + */ + private function makeOrderWithCouponAsGuest(Coupon $coupon) : Order + { + $order = $this->objectManager->create(\Magento\Sales\Model\Order::class); + $order->loadByIncrementId('100000001') + ->setCustomerIsGuest(true) + ->setCouponCode($coupon->getCode()) + ->setCreatedAt('2014-10-25 10:10:10') + ->setAppliedRuleIds($coupon->getRuleId()) + ->save(); + + return $order; + } + + /** + * @param Order $order + */ + private function delegateOrderToBeAssigned(Order $order) + { + $this->delegateCustomerService->delegateNew($order->getId()); + } + + /** + * @return Customer + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\State\InputMismatchException + */ + private function registerNewCustomer() : Customer + { + $customer = $this->objectManager->create( + \Magento\Customer\Api\Data\CustomerInterface::class + ); + + /** @var Magento\Customer\Api\Data\CustomerInterface $customer */ + $customer->setWebsiteId(1) + ->setEmail('customer@example.com') + ->setGroupId(1) + ->setStoreId(1) + ->setPrefix('Mr.') + ->setFirstname('John') + ->setMiddlename('A') + ->setLastname('Smith') + ->setSuffix('Esq.') + ->setDefaultBilling(1) + ->setDefaultShipping(1) + ->setTaxvat('12') + ->setGender(0); + + $customer = $this->customerRepository->save($customer, 'password'); + + return $customer; + } +} + From 11480e8b44d26ecf8e692c1a3406423b1532031f Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Tue, 4 Dec 2018 19:44:54 +0200 Subject: [PATCH 02/15] Refactored Unit-tests, Integration tests --- .../AssignOrderToCustomerObserver.php | 10 +- .../AssignOrderToCustomerObserverTest.php | 20 +++- ...CouponDataAfterOrderCustomerAssignTest.php | 107 ++++++++++++------ 3 files changed, 90 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php b/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php index aba7d551d5330..9857fa39fa51a 100644 --- a/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php +++ b/app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php @@ -27,20 +27,20 @@ class AssignOrderToCustomerObserver implements ObserverInterface /** * @var CustomerAssignment */ - private $customerAssignmentService; + private $assignmentService; /** * AssignOrderToCustomerObserver constructor. * * @param OrderRepositoryInterface $orderRepository - * @param CustomerAssignment $customerAssignmentService + * @param CustomerAssignment $assignmentService */ public function __construct( OrderRepositoryInterface $orderRepository, - CustomerAssignment $customerAssignmentService + CustomerAssignment $assignmentService ) { $this->orderRepository = $orderRepository; - $this->customerAssignmentService = $customerAssignmentService; + $this->assignmentService = $assignmentService; } /** @@ -57,7 +57,7 @@ public function execute(Observer $observer) $orderId = $delegateData['__sales_assign_order_id']; $order = $this->orderRepository->get($orderId); if (!$order->getCustomerId() && $customer->getId()) { - $this->customerAssignmentService->execute($order, $customer); + $this->assignmentService->execute($order, $customer); } } } diff --git a/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php index c6e02151b9bc1..e49eba8880324 100644 --- a/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php +++ b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php @@ -12,6 +12,7 @@ use Magento\Framework\Event\Observer; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\Order\CustomerAssignment; use Magento\Sales\Observer\AssignOrderToCustomerObserver; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject; @@ -27,6 +28,9 @@ class AssignOrderToCustomerObserverTest extends TestCase /** @var OrderRepositoryInterface|PHPUnit_Framework_MockObject_MockObject */ protected $orderRepositoryMock; + /** @var CustomerAssignment | PHPUnit_Framework_MockObject_MockObject */ + protected $customerAssignmentMock; + /** * Set Up */ @@ -35,7 +39,12 @@ protected function setUp() $this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class) ->disableOriginalConstructor() ->getMock(); - $this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock); + + $this->customerAssignmentMock = $this->getMockBuilder(CustomerAssignment::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->customerAssignmentMock); } /** @@ -69,13 +78,12 @@ public function testAssignOrderToCustomerAfterGuestOrder($customerId) $orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId) ->willReturn($orderMock); - if (!$customerId) { - $this->orderRepositoryMock->expects($this->once())->method('save')->with($orderMock); - $this->sut->execute($observerMock); - return ; + if ($customerId) { + $this->customerAssignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock); + } else { + $this->customerAssignmentMock->expects($this->never())->method('execute'); } - $this->orderRepositoryMock->expects($this->never())->method('save')->with($orderMock); $this->sut->execute($observerMock); } diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index d04423daabdf9..f110635a48f8c 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -8,10 +8,20 @@ use Magento\SalesRule\Model\Rule; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Model\Data\Customer; +use Magento\TestFramework\Helper\Bootstrap; - +/** + * Class AssignCouponDataAfterOrderCustomerAssignTest + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\TestCase { + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + private $objectManager; + /** * @var \Magento\Quote\Api\GuestCartManagementInterface */ @@ -22,11 +32,6 @@ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\Te */ private $orderRepository; - /** - * @var \Magento\Framework\ObjectManagerInterface - */ - private $objectManager; - /** * @var \Magento\Framework\Event\ManagerInterface */ @@ -48,11 +53,32 @@ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\Te private $ruleCustomerFactory; /** - * @inheritdoc + * @var Rule */ - protected function setUp() + private $salesRule; + + /** + * @var Coupon + */ + private $coupon; + + /** + * @var Order + */ + private $order; + + /** + * @var Customer + */ + private $customer; + + /** + * AssignCouponDataAfterOrderCustomerAssignTest constructor. + */ + public function __construct($name = null, array $data = [], $dataName = '') { - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + parent::__construct($name, $data, $dataName); + $this->objectManager = Bootstrap::getObjectManager(); $this->eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); $this->orderRepository = $this->objectManager->get(Magento\Sales\Model\OrderRepository::class); $this->delegateCustomerService = $this->objectManager->get(Order\OrderCustomerDelegate::class); @@ -63,25 +89,44 @@ protected function setUp() ); } + /** + * @inheritdoc + */ + protected function setUp() + { + $this->salesRule = $this->prepareSalesRule(); + $this->coupon = $this->attachSalesruleCoupon($this->salesRule); + $this->order = $this->makeOrderWithCouponAsGuest($this->coupon); + $this->delegateOrderToBeAssigned($this->order); + $this->customer = $this->registerNewCustomer(); + $this->order->setCustomerId($this->customer->getId()); + } + + /** + * @inheritdoc + */ + protected function tearDown() + { + unset( + $this->order, + $this->coupon, + $this->customer, + $this->salesRule + ); + } + /** * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/order.php */ public function testCouponDataHasBeenAssignedTest() { - $rule = $this->prepareSalesRule(); - $coupon = $this->attachSalesruleCoupon($rule); - - $order = $this->makeOrderWithCouponAsGuest($coupon); - $this->delegateOrderToBeAssigned($order); - - $customer = $this->registerNewCustomer(); - $ruleCustomer = $this->getSalesruleCustomerUsage($customer, $rule); + $ruleCustomer = $this->getSalesruleCustomerUsage($this->customer, $this->salesRule); // Assert, that rule customer model has been created for specific customer $this->assertEquals( $ruleCustomer->getCustomerId(), - $customer->getId() + $this->customer->getId() ); // Assert, that customer has increased coupon usage of specific rule @@ -97,25 +142,16 @@ public function testCouponDataHasBeenAssignedTest() */ public function testOrderCancelingDecreasesCouponUsages() { - $rule = $this->prepareSalesRule(); - $coupon = $this->attachSalesruleCoupon($rule); - - $order = $this->makeOrderWithCouponAsGuest($coupon); - $this->delegateOrderToBeAssigned($order); - - $customer = $this->registerNewCustomer(); - - $order->setCustomerId($customer->getId()); - $this->processOrder($order); + $this->processOrder($this->order); // Should not throw exception as bux is fixed now - $this->cancelOrder($order); - $ruleCustomer = $this->getSalesruleCustomerUsage($customer, $rule); + $this->cancelOrder($this->order); + $ruleCustomer = $this->getSalesruleCustomerUsage($this->customer, $this->salesRule); // Assert, that rule customer model has been created for specific customer $this->assertEquals( $ruleCustomer->getCustomerId(), - $customer->getId() + $this->customer->getId() ); // Assert, that customer has increased coupon usage of specific rule @@ -123,7 +159,6 @@ public function testOrderCancelingDecreasesCouponUsages() 0, $ruleCustomer->getTimesUsed() ); - } /** @@ -186,7 +221,7 @@ private function prepareSalesRule() : Rule ], ] ); - $this->objectManager->get( + Bootstrap::getObjectManager()->get( \Magento\SalesRule\Model\ResourceModel\Rule::class )->save($salesRule); @@ -204,7 +239,7 @@ private function attachSalesruleCoupon(Rule $salesRule) : Coupon ->setCode('CART_FIXED_DISCOUNT_15') ->setType(0); - $this->objectManager->get(CouponRepositoryInterface::class)->save($coupon); + Bootstrap::getObjectManager()->get(CouponRepositoryInterface::class)->save($coupon); return $coupon; } @@ -215,7 +250,7 @@ private function attachSalesruleCoupon(Rule $salesRule) : Coupon */ private function makeOrderWithCouponAsGuest(Coupon $coupon) : Order { - $order = $this->objectManager->create(\Magento\Sales\Model\Order::class); + $order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class); $order->loadByIncrementId('100000001') ->setCustomerIsGuest(true) ->setCouponCode($coupon->getCode()) @@ -242,7 +277,7 @@ private function delegateOrderToBeAssigned(Order $order) */ private function registerNewCustomer() : Customer { - $customer = $this->objectManager->create( + $customer = Bootstrap::getObjectManager()->create( \Magento\Customer\Api\Data\CustomerInterface::class ); From 10fbf4041c98b12ee4bb19f09f04efc7856dfa60 Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Wed, 5 Dec 2018 16:07:17 +0200 Subject: [PATCH 03/15] Static test improvement. --- .../Sales/Model/Order/CustomerAssignment.php | 3 ++- .../AssignOrderToCustomerObserverTest.php | 14 +++++----- ...CouponDataAfterOrderCustomerAssignTest.php | 26 +++++++------------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/CustomerAssignment.php b/app/code/Magento/Sales/Model/Order/CustomerAssignment.php index b6ae86461c398..8bcfc1dc49de4 100644 --- a/app/code/Magento/Sales/Model/Order/CustomerAssignment.php +++ b/app/code/Magento/Sales/Model/Order/CustomerAssignment.php @@ -49,7 +49,8 @@ public function execute(OrderInterface $order, CustomerInterface $customer)/*: v $this->orderRepository->save($order); $this->eventManager->dispatch( - 'sales_order_customer_assign_after', [ + 'sales_order_customer_assign_after', + [ 'order' => $order, 'customer' => $customer ] diff --git a/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php index e49eba8880324..18371274049e3 100644 --- a/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php +++ b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php @@ -29,7 +29,7 @@ class AssignOrderToCustomerObserverTest extends TestCase protected $orderRepositoryMock; /** @var CustomerAssignment | PHPUnit_Framework_MockObject_MockObject */ - protected $customerAssignmentMock; + protected $assignmentMock; /** * Set Up @@ -40,11 +40,11 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $this->customerAssignmentMock = $this->getMockBuilder(CustomerAssignment::class) + $this->assignmentMock = $this->getMockBuilder(CustomerAssignment::class) ->disableOriginalConstructor() ->getMock(); - $this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->customerAssignmentMock); + $this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->assignmentMock); } /** @@ -78,12 +78,14 @@ public function testAssignOrderToCustomerAfterGuestOrder($customerId) $orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId) ->willReturn($orderMock); + if ($customerId) { - $this->customerAssignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock); - } else { - $this->customerAssignmentMock->expects($this->never())->method('execute'); + $this->assignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock); + $this->sut->execute($observerMock); + return; } + $this->assignmentMock->expects($this->never())->method('execute'); $this->sut->execute($observerMock); } diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index f110635a48f8c..afbb938c740b5 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -1,7 +1,8 @@ objectManager = Bootstrap::getObjectManager(); $this->eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); - $this->orderRepository = $this->objectManager->get(Magento\Sales\Model\OrderRepository::class); + $this->orderRepository = $this->objectManager->get(\Magento\Sales\Model\OrderRepository::class); $this->delegateCustomerService = $this->objectManager->get(Order\OrderCustomerDelegate::class); $this->customerRepository = $this->objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class); - $this->ruleCustomerFactory = $this->objectManager->get(Magento\SalesRule\Model\Rule\CustomerFactory::class);; + $this->ruleCustomerFactory = $this->objectManager->get(\Magento\SalesRule\Model\Rule\CustomerFactory::class); $this->assignCouponToCustomerObserver = $this->objectManager->get( - Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class + \Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class ); } @@ -116,7 +119,6 @@ protected function tearDown() } /** - * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/order.php */ public function testCouponDataHasBeenAssignedTest() @@ -137,7 +139,6 @@ public function testCouponDataHasBeenAssignedTest() } /** - * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/order.php */ public function testOrderCancelingDecreasesCouponUsages() @@ -145,7 +146,7 @@ public function testOrderCancelingDecreasesCouponUsages() $this->processOrder($this->order); // Should not throw exception as bux is fixed now - $this->cancelOrder($this->order); + $this->order->cancel(); $ruleCustomer = $this->getSalesruleCustomerUsage($this->customer, $this->salesRule); // Assert, that rule customer model has been created for specific customer @@ -172,20 +173,12 @@ private function processOrder(Order $order) return $this->orderRepository->save($order); } - /** - * @param Order $order - */ - private function cancelOrder(Order $order) - { - $order->cancel(); - } - /** * @param Customer $customer * @param Rule $rule * @return Rule\Customer */ - private function getSalesruleCustomerUsage(Customer $customer, Rule $rule) : Magento\SalesRule\Model\Rule\Customer + private function getSalesruleCustomerUsage(Customer $customer, Rule $rule) : \Magento\SalesRule\Model\Rule\Customer { $ruleCustomer = $this->ruleCustomerFactory->create(); return $ruleCustomer->loadByCustomerRule($customer->getId(), $rule->getRuleId()); @@ -301,4 +294,3 @@ private function registerNewCustomer() : Customer return $customer; } } - From 1e2f3fbd5481b3eee6d7c049703c0d51b849c439 Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Fri, 7 Dec 2018 11:14:47 +0200 Subject: [PATCH 04/15] Added supression of static method access. --- .../AssignCouponDataAfterOrderCustomerAssignTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index afbb938c740b5..47498ef3c51ba 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -17,6 +17,7 @@ * @magentoAppIsolation enabled * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.StaticAccess) */ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\TestCase { @@ -168,8 +169,8 @@ public function testOrderCancelingDecreasesCouponUsages() */ private function processOrder(Order $order) { - $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING); - $order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING); + $order->setState(Order::STATE_PROCESSING); + $order->setStatus(Order::STATE_PROCESSING); return $this->orderRepository->save($order); } From 5ea6e7208099123c5e7f8df34607fca9ef03c650 Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Fri, 14 Dec 2018 12:39:01 +0200 Subject: [PATCH 05/15] Changed way to get to clean up the conceptions. --- .../AssignCouponDataAfterOrderCustomerAssignTest.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index 47498ef3c51ba..332e5a254fa22 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -17,7 +17,6 @@ * @magentoAppIsolation enabled * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @SuppressWarnings(PHPMD.StaticAccess) */ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\TestCase { @@ -111,12 +110,10 @@ protected function setUp() */ protected function tearDown() { - unset( - $this->order, - $this->coupon, - $this->customer, - $this->salesRule - ); + $this->salesRule = null; + $this->customer = null; + $this->coupon = null; + $this->order = null; } /** From 0e027a091831828b163efb39bc1b5b4ce3468e4c Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 7 Nov 2018 13:06:46 +0200 Subject: [PATCH 06/15] Comparing the current block path with the current url path --- .../View/Element/Html/Link/Current.php | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php index 43bfd46c1193a..cb29c67a2ca30 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php @@ -5,6 +5,10 @@ */ namespace Magento\Framework\View\Element\Html\Link; +use Magento\Framework\App\DefaultPathInterface; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; + /** * Block representing link with two possible states. * "Current" state means link leads to URL equivalent to URL of currently displayed page. @@ -17,25 +21,25 @@ * @method null|bool getCurrent() * @method \Magento\Framework\View\Element\Html\Link\Current setCurrent(bool $value) */ -class Current extends \Magento\Framework\View\Element\Template +class Current extends Template { /** * Default path * - * @var \Magento\Framework\App\DefaultPathInterface + * @var DefaultPathInterface */ protected $_defaultPath; /** * Constructor * - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Framework\App\DefaultPathInterface $defaultPath + * @param Context $context + * @param DefaultPathInterface $defaultPath * @param array $data */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Framework\App\DefaultPathInterface $defaultPath, + Context $context, + DefaultPathInterface $defaultPath, array $data = [] ) { parent::__construct($context, $data); @@ -81,7 +85,7 @@ private function getMca() */ public function isCurrent() { - return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getMca()); + return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getPathInfo()); } /** @@ -147,4 +151,14 @@ private function getAttributesHtml() return $attributesHtml; } + + /** + * Get current page path info + * + * @return string + */ + private function getPathInfo() + { + return trim($this->_request->getPathInfo(), '/'); + } } From 1357888cb3f38f1b3589ebfbc84d93a97382d427 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Fri, 9 Nov 2018 15:04:09 +0200 Subject: [PATCH 07/15] Adjusting the Unit Test for the isCurrent method --- .../Unit/Element/Html/Link/CurrentTest.php | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php index 909748722a081..9c720f0f48dc3 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php @@ -17,11 +17,6 @@ class CurrentTest extends \PHPUnit\Framework\TestCase */ protected $_requestMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_defaultPathMock; - /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ @@ -32,7 +27,6 @@ protected function setUp() $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->_urlBuilderMock = $this->createMock(\Magento\Framework\UrlInterface::class); $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class); - $this->_defaultPathMock = $this->createMock(\Magento\Framework\App\DefaultPathInterface::class); } public function testGetUrl() @@ -60,31 +54,54 @@ public function testIsCurrentIfIsset() $this->assertTrue($link->isCurrent()); } - public function testIsCurrent() + /** + * Test if the current url is the same as link path + * + * @dataProvider linkPathProvider + * @param string $linkPath + * @param string $currentPathInfo + * @param bool $expected + * @return void + */ + public function testIsCurrent($linkPath, $currentPathInfo, $expected) { - $path = 'test/path'; - $url = 'http://example.com/a/b'; - - $this->_requestMock->expects($this->once())->method('getModuleName')->will($this->returnValue('a')); - $this->_requestMock->expects($this->once())->method('getControllerName')->will($this->returnValue('b')); - $this->_requestMock->expects($this->once())->method('getActionName')->will($this->returnValue('d')); - $this->_defaultPathMock->expects($this->atLeastOnce())->method('getPart')->will($this->returnValue('d')); - - $this->_urlBuilderMock->expects($this->at(0))->method('getUrl')->with($path)->will($this->returnValue($url)); - $this->_urlBuilderMock->expects($this->at(1))->method('getUrl')->with('a/b')->will($this->returnValue($url)); - - $this->_requestMock->expects($this->once())->method('getControllerName')->will($this->returnValue('b')); + $baseUrl = 'http://example.com/'; + $trimmed = trim($currentPathInfo, '/'); + + $this->_requestMock->expects($this->any())->method('getPathInfo')->willReturn($currentPathInfo); + $this->_urlBuilderMock->expects($this->at(0)) + ->method('getUrl') + ->with($linkPath) + ->will($this->returnValue($baseUrl . $linkPath)); + $this->_urlBuilderMock->expects($this->at(1)) + ->method('getUrl') + ->with($trimmed) + ->will($this->returnValue($baseUrl . $trimmed)); /** @var \Magento\Framework\View\Element\Html\Link\Current $link */ $link = $this->_objectManager->getObject( \Magento\Framework\View\Element\Html\Link\Current::class, [ 'urlBuilder' => $this->_urlBuilderMock, - 'request' => $this->_requestMock, - 'defaultPath' => $this->_defaultPathMock + 'request' => $this->_requestMock ] ); - $link->setPath($path); - $this->assertTrue($link->isCurrent()); + + $link->setCurrent(false); + $link->setPath($linkPath); + $this->assertEquals($expected, $link->isCurrent()); + } + + /** + * @return array + */ + public function linkPathProvider() + { + return [ + ['test/index', '/test/index/', true], + ['test/index/index', '/test/index/index/', true], + ['test/route', '/test/index/', false], + ['test/index', '/test/', false] + ]; } public function testIsCurrentFalse() From 83cbf32256b286c9a853f3f4b001361815ba6c2b Mon Sep 17 00:00:00 2001 From: eduard13 Date: Mon, 12 Nov 2018 13:52:54 +0200 Subject: [PATCH 08/15] Improving the current link logic, by covering all the possible cases for default parts --- .../View/Element/Html/Link/Current.php | 21 +++------ .../Unit/Element/Html/Link/CurrentTest.php | 47 ++++++++----------- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php index cb29c67a2ca30..d5da6cefae5b9 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php @@ -64,14 +64,15 @@ public function getHref() private function getMca() { $routeParts = [ - 'module' => $this->_request->getModuleName(), - 'controller' => $this->_request->getControllerName(), - 'action' => $this->_request->getActionName(), + $this->_request->getModuleName(), + $this->_request->getControllerName(), + $this->_request->getActionName(), ]; $parts = []; + $pathParts = explode('/', $this->getPath()); foreach ($routeParts as $key => $value) { - if (!empty($value) && $value != $this->_defaultPath->getPart($key)) { + if (isset($pathParts[$key]) && $pathParts[$key] === $value) { $parts[] = $value; } } @@ -85,7 +86,7 @@ private function getMca() */ public function isCurrent() { - return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getPathInfo()); + return $this->getCurrent() || $this->getUrl($this->getPath()) == $this->getUrl($this->getMca()); } /** @@ -151,14 +152,4 @@ private function getAttributesHtml() return $attributesHtml; } - - /** - * Get current page path info - * - * @return string - */ - private function getPathInfo() - { - return trim($this->_request->getPathInfo(), '/'); - } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php index 9c720f0f48dc3..e11468061c9ec 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php @@ -57,26 +57,31 @@ public function testIsCurrentIfIsset() /** * Test if the current url is the same as link path * - * @dataProvider linkPathProvider - * @param string $linkPath - * @param string $currentPathInfo - * @param bool $expected * @return void */ - public function testIsCurrent($linkPath, $currentPathInfo, $expected) + public function testIsCurrent() { - $baseUrl = 'http://example.com/'; - $trimmed = trim($currentPathInfo, '/'); + $path = 'test/index'; + $url = 'http://example.com/test/index'; - $this->_requestMock->expects($this->any())->method('getPathInfo')->willReturn($currentPathInfo); + $this->_requestMock->expects($this->once()) + ->method('getModuleName') + ->will($this->returnValue('test')); + $this->_requestMock->expects($this->once()) + ->method('getControllerName') + ->will($this->returnValue('index')); + $this->_requestMock->expects($this->once()) + ->method('getActionName') + ->will($this->returnValue('index')); $this->_urlBuilderMock->expects($this->at(0)) ->method('getUrl') - ->with($linkPath) - ->will($this->returnValue($baseUrl . $linkPath)); + ->with($path) + ->will($this->returnValue($url)); $this->_urlBuilderMock->expects($this->at(1)) ->method('getUrl') - ->with($trimmed) - ->will($this->returnValue($baseUrl . $trimmed)); + ->with('test/index') + ->will($this->returnValue($url)); + /** @var \Magento\Framework\View\Element\Html\Link\Current $link */ $link = $this->_objectManager->getObject( \Magento\Framework\View\Element\Html\Link\Current::class, @@ -86,22 +91,8 @@ public function testIsCurrent($linkPath, $currentPathInfo, $expected) ] ); - $link->setCurrent(false); - $link->setPath($linkPath); - $this->assertEquals($expected, $link->isCurrent()); - } - - /** - * @return array - */ - public function linkPathProvider() - { - return [ - ['test/index', '/test/index/', true], - ['test/index/index', '/test/index/index/', true], - ['test/route', '/test/index/', false], - ['test/index', '/test/', false] - ]; + $link->setPath($path); + $this->assertTrue($link->isCurrent()); } public function testIsCurrentFalse() From 02bc6fa5759ca6da18ec87ae5217a2326653ad76 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 11 Dec 2018 14:36:09 +0200 Subject: [PATCH 09/15] Fix static test. --- .../Magento/Framework/View/Element/Html/Link/Current.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php index d5da6cefae5b9..d18221578bb92 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php @@ -60,13 +60,14 @@ public function getHref() * Get current mca * * @return string + * @SuppressWarnings(PHPMD.RequestAwareBlockMethod) */ private function getMca() { $routeParts = [ - $this->_request->getModuleName(), - $this->_request->getControllerName(), - $this->_request->getActionName(), + (string)$this->_request->getModuleName(), + (string)$this->_request->getControllerName(), + (string)$this->_request->getActionName(), ]; $parts = []; From cf1e877a76b6b5bb5f6802fd49bec81be70c8110 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 13 Dec 2018 23:22:22 +0200 Subject: [PATCH 10/15] Fixing the active state for the links with the same frontname --- .../Magento/Framework/View/Element/Html/Link/Current.php | 2 +- .../Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php index d18221578bb92..7aac210dcab89 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php @@ -71,7 +71,7 @@ private function getMca() ]; $parts = []; - $pathParts = explode('/', $this->getPath()); + $pathParts = explode('/', trim($this->_request->getPathInfo(), '/')); foreach ($routeParts as $key => $value) { if (isset($pathParts[$key]) && $pathParts[$key] === $value) { $parts[] = $value; diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php index e11468061c9ec..7070ec9d48c11 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/Link/CurrentTest.php @@ -64,6 +64,9 @@ public function testIsCurrent() $path = 'test/index'; $url = 'http://example.com/test/index'; + $this->_requestMock->expects($this->once()) + ->method('getPathInfo') + ->will($this->returnValue('/test/index/')); $this->_requestMock->expects($this->once()) ->method('getModuleName') ->will($this->returnValue('test')); From 9a63dad6a2958d07aa631bb0e971f17e3f6eda3b Mon Sep 17 00:00:00 2001 From: Andriy Kravets Date: Wed, 26 Dec 2018 11:28:08 +0200 Subject: [PATCH 11/15] Moved object manager to setup method. --- .../AssignCouponDataAfterOrderCustomerAssignTest.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index 332e5a254fa22..06478dc1f1571 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -75,12 +75,12 @@ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\Te */ private $customer; + /** - * AssignCouponDataAfterOrderCustomerAssignTest constructor. + * @inheritdoc */ - public function __construct($name = null, array $data = [], $dataName = '') + protected function setUp() { - parent::__construct($name, $data, $dataName); $this->objectManager = Bootstrap::getObjectManager(); $this->eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); $this->orderRepository = $this->objectManager->get(\Magento\Sales\Model\OrderRepository::class); @@ -90,13 +90,7 @@ public function __construct($name = null, array $data = [], $dataName = '') $this->assignCouponToCustomerObserver = $this->objectManager->get( \Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver::class ); - } - /** - * @inheritdoc - */ - protected function setUp() - { $this->salesRule = $this->prepareSalesRule(); $this->coupon = $this->attachSalesruleCoupon($this->salesRule); $this->order = $this->makeOrderWithCouponAsGuest($this->coupon); From 36c2329505ca63c821fc8d7a553e6f35a4f3ae40 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 3 Jan 2019 13:20:49 +0000 Subject: [PATCH 12/15] magento/magento2#19423: Removed extra blank line --- .../Observer/AssignCouponDataAfterOrderCustomerAssignTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index 06478dc1f1571..840ee1a5607d9 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -75,7 +75,6 @@ class AssignCouponDataAfterOrderCustomerAssignTest extends \PHPUnit\Framework\Te */ private $customer; - /** * @inheritdoc */ From 4802e00643bae377a254e8d9b92e2bad72c33e65 Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Sat, 22 Dec 2018 13:59:48 +0530 Subject: [PATCH 13/15] issue resolved:Undefined Variable $itemsOrderItemId issue resolved:Undefined Variable $itemsOrderItemId --- app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php b/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php index b4ff445c63f4e..c561a0982dce2 100644 --- a/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php +++ b/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php @@ -86,7 +86,7 @@ public function getConfigDataJson() $itemsName = []; $itemsWeight = []; $itemsProductId = []; - + $itemsOrderItemId = []; if ($shipmentId) { $urlParams['shipment_id'] = $shipmentId; $createLabelUrl = $this->getUrl('adminhtml/order_shipment/createLabel', $urlParams); From cb15b010ddf4bbe9caddac141dfb829926c4a631 Mon Sep 17 00:00:00 2001 From: Milind Singh Date: Sat, 5 Jan 2019 18:15:57 +0530 Subject: [PATCH 14/15] Static test suppressed --- app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php b/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php index c561a0982dce2..e5e419328eea4 100644 --- a/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php +++ b/app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php @@ -74,6 +74,7 @@ public function getShipment() * Configuration for popup window for packaging * * @return string + * @SuppressWarnings(PHPMD.RequestAwareBlockMethod) */ public function getConfigDataJson() { From fdf7da48088ffae823021e5a8be4429afa941404 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 8 Jan 2019 15:29:29 +0200 Subject: [PATCH 15/15] ENGCOM-3784: Static test fix. --- .../Observer/AssignCouponDataAfterOrderCustomerAssignTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php index 840ee1a5607d9..397650df416e9 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Observer/AssignCouponDataAfterOrderCustomerAssignTest.php @@ -1,4 +1,8 @@