0

As a developer many times, I need to test created module/functionality. For example I need to create an observer which listening to sales_order_place_after. For check whether observer is working correctly or not I need to place actual order.

Sometimes to test code, I need to place 50-60 orders.

Is there any way in which I can test my code without actual order ?

because creating an order is a time consuming process.

Thanks in advance.

1

To test your code you can follow this approach:

  1. Create a module and by placing 1 or 2 order just check if your module is working fine and observer is calling sales_order_place_after event correctly.

  2. Once your observer is working correctly, you can copy the whole code from your observer and paste either in test controller or in test root file and load order using static order id above your code and then you can test your code for that particular order data, until you achieve what you want.

  3. Once your functionality is done and verified in step 2 then you can place the update code from step 2 again in your observer and place 2-3 orders to do final verification of the real-time functionality.

OR

If you don't want to do above method then you can use reorder functionality so that you can at least save some time while placing an order, as to check sales_order_place_after observer you have to place order otherwise this event will not hit.

  • Thank you Aman. But if i want to test my order for diffrent case like shipping/payment method choose.it will not work because every time same data – Pawan Feb 21 '18 at 3:38
  • Is there any wayv in we can test with existing orders ? – Pawan Feb 21 '18 at 3:39
  • you can use 2-3 orders for different Shipping and Payment method and load that order to test. You can also test with existing orders also, by loading that particular order from order id. Something like this: $orderId = 1; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId); – aman Feb 21 '18 at 4:33
  • Aman, i think there should be a beter way. Anyways thanks upvoted – Pawan Feb 25 '18 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.