Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubtractQtyFromQuotesObserverTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class SubtractQtyFromQuotesObserverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
20  protected $_quoteMock;
21 
25  protected $_observerMock;
26 
30  protected $_eventMock;
31 
32  protected function setUp()
33  {
34  $this->_quoteMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote::class);
35  $this->_observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
36  $this->_eventMock = $this->createPartialMock(
37  \Magento\Framework\Event::class,
38  ['getProduct', 'getStatus', 'getProductId']
39  );
40  $this->_observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->_eventMock));
41  $this->_model = new SubtractQtyFromQuotesObserver($this->_quoteMock);
42  }
43 
44  public function testSubtractQtyFromQuotes()
45  {
46  $productMock = $this->createPartialMock(
47  \Magento\Catalog\Model\Product::class,
48  ['getId', 'getStatus', '__wakeup']
49  );
50  $this->_eventMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
51  $this->_quoteMock->expects($this->once())->method('subtractProductFromQuotes')->with($productMock);
52  $this->_model->execute($this->_observerMock);
53  }
54 }