CustomerLoginSuccessObserverTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Observer;
  7. use Magento\Customer\Model\AuthenticationInterface;
  8. use Magento\Framework\Event\Observer;
  9. use Magento\Customer\Observer\CustomerLoginSuccessObserver;
  10. /**
  11. * Class CustomerLoginSuccessObserverTest
  12. */
  13. class CustomerLoginSuccessObserverTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * Authentication
  17. *
  18. * @var AuthenticationInterface
  19. */
  20. protected $authenticationMock;
  21. /**
  22. * @var \Magento\Customer\Model\Customer
  23. */
  24. protected $customerModelMock;
  25. /**
  26. * @var CustomerLoginSuccessObserver
  27. */
  28. protected $customerLoginSuccessObserver;
  29. /**
  30. * @return void
  31. */
  32. public function setUp()
  33. {
  34. $this->authenticationMock = $this->createMock(AuthenticationInterface::class);
  35. $this->customerModelMock = $this->createPartialMock(\Magento\Customer\Model\Customer::class, ['getId']);
  36. $this->customerLoginSuccessObserver = new CustomerLoginSuccessObserver(
  37. $this->authenticationMock
  38. );
  39. }
  40. /**
  41. * @return void
  42. */
  43. public function testExecute()
  44. {
  45. $customerId = 1;
  46. $observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
  47. $eventMock = $this->createPartialMock(\Magento\Framework\Event::class, ['getData']);
  48. $observerMock->expects($this->once())
  49. ->method('getEvent')
  50. ->willReturn($eventMock);
  51. $eventMock->expects($this->once())
  52. ->method('getData')
  53. ->with('model')
  54. ->willReturn($this->customerModelMock);
  55. $this->customerModelMock->expects($this->once())
  56. ->method('getId')
  57. ->willReturn($customerId);
  58. $this->authenticationMock->expects($this->once())
  59. ->method('unlock')
  60. ->with($customerId);
  61. $this->customerLoginSuccessObserver->execute($observerMock);
  62. }
  63. }