Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerAuthenticatedEventObserverTest.php
Go to the documentation of this file.
1 <?php
9 
10 class CustomerAuthenticatedEventObserverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
21 
25  protected $observerMock;
26 
30  protected $quoteManagerMock;
31 
35  protected $requestMock;
36 
37  protected function setUp()
38  {
39  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
40  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
41  $this->quoteManagerMock = $this->createMock(\Magento\Persistent\Model\QuoteManager::class);
42  $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
43  $this->model = new \Magento\Persistent\Observer\CustomerAuthenticatedEventObserver(
44  $this->customerSessionMock,
45  $this->requestMock,
46  $this->quoteManagerMock
47  );
48  }
49 
50  public function testExecute()
51  {
52  $this->customerSessionMock
53  ->expects($this->once())
54  ->method('setCustomerId')
55  ->with(null)
56  ->will($this->returnSelf());
57  $this->customerSessionMock
58  ->expects($this->once())
59  ->method('setCustomerGroupId')
60  ->with(null)
61  ->will($this->returnSelf());
62  $this->requestMock
63  ->expects($this->once())
64  ->method('getParam')
65  ->with('context')
66  ->will($this->returnValue('not_checkout'));
67  $this->quoteManagerMock->expects($this->once())->method('expire');
68  $this->quoteManagerMock->expects($this->never())->method('setGuest');
69  $this->model->execute($this->observerMock);
70  }
71 
72  public function testExecuteDuringCheckout()
73  {
74  $this->customerSessionMock
75  ->expects($this->once())
76  ->method('setCustomerId')
77  ->with(null)
78  ->will($this->returnSelf());
79  $this->customerSessionMock
80  ->expects($this->once())
81  ->method('setCustomerGroupId')
82  ->with(null)
83  ->will($this->returnSelf());
84  $this->requestMock
85  ->expects($this->once())
86  ->method('getParam')
87  ->with('context')
88  ->will($this->returnValue('checkout'));
89  $this->quoteManagerMock->expects($this->never())->method('expire');
90  $this->quoteManagerMock->expects($this->once())->method('setGuest');
91  $this->model->execute($this->observerMock);
92  }
93 }