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