i have a working Observer on the event sales_order_save_after. The Observer looks like this:

namespace Company\ExportOrder\Observer;
use Magento\Framework\Event\ObserverInterface; 

class Observer implements ObserverInterface { 

    protected $connector; public function __construct() { 
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 

    public function execute(\Magento\Framework\Event\Observer $observer) { 
        $order = $observer->getEvent()->getOrder();
        $orderId = $order->getId();
        $customerId = $order->getCustomerId();

        // do something

How am i able to call this Observer manually for testing? I don´t really want to create orders again and again. Idea is something like this:

$model = $objectManager->create('\Company\ExportOrder\Observer\Observer');

But the execute-Function expects the Observer Model, and how can i set the order id manually for testing the function?

2 Answers 2


Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after

$orderId = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId);
$orderState = "holded";

Try following way:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Sales\Model\Order $order */
$order = $objectManager->create('Magento\Sales\Model\Order')->load(1884);
$eventManager = $objectManager->create('Magento\Framework\Event\ManagerInterface');
$eventManager->dispatch('sales_order_save_after', ['order' => $order]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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