Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerAuthUpdateTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $customerRegistry;
24 
29 
33  protected $objectManager;
34 
38  protected function setUp()
39  {
40  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
41 
42  $this->customerRegistry =
43  $this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
44  $this->customerResourceModel =
45  $this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
46 
47  $this->model = $this->objectManager->getObject(
48  \Magento\Customer\Model\CustomerAuthUpdate::class,
49  [
50  'customerRegistry' => $this->customerRegistry,
51  'customerResourceModel' => $this->customerResourceModel,
52  ]
53  );
54  }
55 
59  public function testSaveAuth()
60  {
61  $customerId = 1;
62 
63  $customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
64 
65  $dbAdapter = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
66 
67  $this->customerRegistry->expects($this->once())
68  ->method('retrieveSecureData')
69  ->willReturn($customerSecureMock);
70 
71  $customerSecureMock->expects($this->exactly(3))
72  ->method('getData')
73  ->willReturn(1);
74 
75  $this->customerResourceModel->expects($this->any())
76  ->method('getConnection')
77  ->willReturn($dbAdapter);
78 
79  $this->customerResourceModel->expects($this->any())
80  ->method('getTable')
81  ->willReturn('customer_entity');
82 
83  $dbAdapter->expects($this->any())
84  ->method('update')
85  ->with(
86  'customer_entity',
87  [
88  'failures_num' => 1,
89  'first_failure' => 1,
90  'lock_expires' => 1
91  ]
92  );
93 
94  $dbAdapter->expects($this->any())
95  ->method('quoteInto')
96  ->with(
97  'entity_id = ?',
99  );
100 
101  $this->model->saveAuth($customerId);
102  }
103 }