Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerLoginSuccessObserverTest.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class CustomerLoginSuccessObserverTest extends \PHPUnit\Framework\TestCase
16 {
23 
27  protected $customerModelMock;
28 
33 
37  public function setUp()
38  {
39  $this->authenticationMock = $this->createMock(AuthenticationInterface::class);
40 
41  $this->customerModelMock = $this->createPartialMock(\Magento\Customer\Model\Customer::class, ['getId']);
42  $this->customerLoginSuccessObserver = new CustomerLoginSuccessObserver(
43  $this->authenticationMock
44  );
45  }
46 
50  public function testExecute()
51  {
52  $customerId = 1;
53  $observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
54  $eventMock = $this->createPartialMock(\Magento\Framework\Event::class, ['getData']);
55  $observerMock->expects($this->once())
56  ->method('getEvent')
57  ->willReturn($eventMock);
58  $eventMock->expects($this->once())
59  ->method('getData')
60  ->with('model')
61  ->willReturn($this->customerModelMock);
62  $this->customerModelMock->expects($this->once())
63  ->method('getId')
64  ->willReturn($customerId);
65  $this->authenticationMock->expects($this->once())
66  ->method('unlock')
67  ->with($customerId);
68  $this->customerLoginSuccessObserver->execute($observerMock);
69  }
70 }