CustomerAuthUpdateTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model;
  7. use Magento\Customer\Model\CustomerAuthUpdate;
  8. /**
  9. * Class CustomerAuthUpdateTest
  10. */
  11. class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var CustomerAuthUpdate
  15. */
  16. protected $model;
  17. /**
  18. * @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerRegistry;
  21. /**
  22. * @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $customerResourceModel;
  25. /**
  26. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  27. */
  28. protected $objectManager;
  29. /**
  30. * Setup the test
  31. */
  32. protected function setUp()
  33. {
  34. $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  35. $this->customerRegistry =
  36. $this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
  37. $this->customerResourceModel =
  38. $this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
  39. $this->model = $this->objectManager->getObject(
  40. \Magento\Customer\Model\CustomerAuthUpdate::class,
  41. [
  42. 'customerRegistry' => $this->customerRegistry,
  43. 'customerResourceModel' => $this->customerResourceModel,
  44. ]
  45. );
  46. }
  47. /**
  48. * test SaveAuth
  49. */
  50. public function testSaveAuth()
  51. {
  52. $customerId = 1;
  53. $customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
  54. $dbAdapter = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
  55. $this->customerRegistry->expects($this->once())
  56. ->method('retrieveSecureData')
  57. ->willReturn($customerSecureMock);
  58. $customerSecureMock->expects($this->exactly(3))
  59. ->method('getData')
  60. ->willReturn(1);
  61. $this->customerResourceModel->expects($this->any())
  62. ->method('getConnection')
  63. ->willReturn($dbAdapter);
  64. $this->customerResourceModel->expects($this->any())
  65. ->method('getTable')
  66. ->willReturn('customer_entity');
  67. $dbAdapter->expects($this->any())
  68. ->method('update')
  69. ->with(
  70. 'customer_entity',
  71. [
  72. 'failures_num' => 1,
  73. 'first_failure' => 1,
  74. 'lock_expires' => 1
  75. ]
  76. );
  77. $dbAdapter->expects($this->any())
  78. ->method('quoteInto')
  79. ->with(
  80. 'entity_id = ?',
  81. $customerId
  82. );
  83. $this->model->saveAuth($customerId);
  84. }
  85. }