Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckoutAllSubmitAfterObserverTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class CheckoutAllSubmitAfterObserverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $observer;
16 
21 
26 
30  protected $event;
31 
35  protected $eventObserver;
36 
37  protected function setUp()
38  {
39  $this->subtractQuoteInventoryObserver = $this->createMock(
40  \Magento\CatalogInventory\Observer\SubtractQuoteInventoryObserver::class
41  );
42 
43  $this->reindexQuoteInventoryObserver = $this->createMock(
44  \Magento\CatalogInventory\Observer\ReindexQuoteInventoryObserver::class
45  );
46 
47  $this->event = $this->getMockBuilder(\Magento\Framework\Event::class)
48  ->disableOriginalConstructor()
49  ->setMethods(['getProduct', 'getCollection', 'getCreditmemo', 'getQuote', 'getWebsite'])
50  ->getMock();
51 
52  $this->eventObserver = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
53  ->disableOriginalConstructor()
54  ->setMethods(['getEvent'])
55  ->getMock();
56 
57  $this->eventObserver->expects($this->atLeastOnce())
58  ->method('getEvent')
59  ->will($this->returnValue($this->event));
60 
61  $this->observer = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
62  \Magento\CatalogInventory\Observer\CheckoutAllSubmitAfterObserver::class,
63  [
64  'subtractQuoteInventoryObserver' => $this->subtractQuoteInventoryObserver,
65  'reindexQuoteInventoryObserver' => $this->reindexQuoteInventoryObserver,
66  ]
67  );
68  }
69 
70  public function testCheckoutAllSubmitAfter()
71  {
72  $quote = $this->createPartialMock(\Magento\Quote\Model\Quote::class, ['getInventoryProcessed']);
73  $quote->expects($this->once())
74  ->method('getInventoryProcessed')
75  ->will($this->returnValue(false));
76 
77  $this->event->expects($this->once())
78  ->method('getQuote')
79  ->will($this->returnValue($quote));
80 
81  $this->subtractQuoteInventoryObserver->expects($this->once())
82  ->method('execute')
83  ->with($this->eventObserver);
84 
85  $this->reindexQuoteInventoryObserver->expects($this->once())
86  ->method('execute')
87  ->with($this->eventObserver);
88 
89  $this->observer->execute($this->eventObserver);
90  }
91 }
$quote