Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LoadCustomerQuoteObserverTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class LoadCustomerQuoteObserverTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $object;
14 
16  protected $objectManager;
17 
19  protected $checkoutSession;
20 
22  protected $messageManager;
23 
24  protected function setUp()
25  {
26  $this->objectManager = new ObjectManager($this);
27  $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
28  $this->messageManager = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
29  $this->object = $this->objectManager->getObject(
30  \Magento\Checkout\Observer\LoadCustomerQuoteObserver::class,
31  [
32  'checkoutSession' => $this->checkoutSession,
33  'messageManager' => $this->messageManager
34  ]
35  );
36  }
37 
39  {
40  $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->willThrowException(
41  new \Magento\Framework\Exception\LocalizedException(__('Message'))
42  );
43  $this->messageManager->expects($this->once())->method('addErrorMessage')->with('Message');
44 
45  $observerMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->object->execute($observerMock);
50  }
51 
53  {
54  $exception = new \Exception('Message');
55  $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will(
56  $this->throwException($exception)
57  );
58  $this->messageManager->expects($this->once())->method('addExceptionMessage')
59  ->with($exception, 'Load customer quote error');
60 
61  $observerMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64 
65  $this->object->execute($observerMock);
66  }
67 }
__()
Definition: __.php:13