_quoteMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote::class); $this->_observerMock = $this->createMock(\Magento\Framework\Event\Observer::class); $this->_eventMock = $this->createPartialMock( \Magento\Framework\Event::class, ['getProduct', 'getStatus', 'getProductId'] ); $this->_observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->_eventMock)); $this->_model = new SubtractQtyFromQuotesObserver($this->_quoteMock); } public function testSubtractQtyFromQuotes() { $productMock = $this->createPartialMock( \Magento\Catalog\Model\Product::class, ['getId', 'getStatus', '__wakeup'] ); $this->_eventMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock)); $this->_quoteMock->expects($this->once())->method('subtractProductFromQuotes')->with($productMock); $this->_model->execute($this->_observerMock); } }