Skip to content

Commit 91361c4

Browse files
committed
MAGETWO-56126: Login failed after new custom attribute was added
- fixing Authentification backward incompatible and unit test
1 parent 24c8b2e commit 91361c4

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

app/code/Magento/Customer/Model/Authentication.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Customer\Model;
77

8+
use Magento\Customer\Api\CustomerRepositoryInterface;
89
use Magento\Customer\Model\ResourceModel\CustomerRepository;
910
use Magento\Customer\Model\CustomerAuthUpdate;
1011
use Magento\Backend\App\ConfigInterface;
@@ -47,7 +48,7 @@ class Authentication implements AuthenticationInterface
4748
protected $encryptor;
4849

4950
/**
50-
* @var CustomerRepository
51+
* @var CustomerRepositoryInterface
5152
*/
5253
protected $customerRepository;
5354

@@ -57,14 +58,14 @@ class Authentication implements AuthenticationInterface
5758
private $customerAuthUpdate;
5859

5960
/**
60-
* @param CustomerRepository $customerRepository
61+
* @param CustomerRepositoryInterface $customerRepository
6162
* @param CustomerRegistry $customerRegistry
6263
* @param ConfigInterface $backendConfig
6364
* @param \Magento\Framework\Stdlib\DateTime $dateTime
6465
* @param Encryptor $encryptor
6566
*/
6667
public function __construct(
67-
CustomerRepository $customerRepository,
68+
CustomerRepositoryInterface $customerRepository,
6869
CustomerRegistry $customerRegistry,
6970
ConfigInterface $backendConfig,
7071
\Magento\Framework\Stdlib\DateTime $dateTime,
@@ -171,7 +172,7 @@ public function authenticate($customerId, $password)
171172
}
172173
return true;
173174
}
174-
175+
175176
/**
176177
* Get customer authentication update model
177178
*

app/code/Magento/Customer/Test/Unit/Model/AuthenticationTest.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,20 @@ class AuthenticationTest extends \PHPUnit_Framework_TestCase
5555
*/
5656
private $dateTimeMock;
5757

58+
/**
59+
* @var \Magento\Customer\Model\CustomerAuthUpdate | \PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $customerAuthUpdate;
62+
63+
/**
64+
* @var ObjectManagerHelper
65+
*/
66+
protected $objectManager;
67+
5868
protected function setUp()
5969
{
70+
$this->objectManager = new ObjectManagerHelper($this);
71+
6072
$this->backendConfigMock = $this->getMockBuilder(ConfigInterface::class)
6173
->disableOriginalConstructor()
6274
->setMethods(['getValue'])
@@ -98,9 +110,11 @@ protected function setUp()
98110
false
99111
);
100112

101-
$objectManagerHelper = new ObjectManagerHelper($this);
113+
$this->customerAuthUpdate = $this->getMockBuilder(\Magento\Customer\Model\CustomerAuthUpdate::class)
114+
->disableOriginalConstructor()
115+
->getMock();
102116

103-
$this->authentication = $objectManagerHelper->getObject(
117+
$this->authentication = $this->objectManager->getObject(
104118
Authentication::class,
105119
[
106120
'customerRegistry' => $this->customerRegistryMock,
@@ -110,6 +124,12 @@ protected function setUp()
110124
'dateTime' => $this->dateTimeMock,
111125
]
112126
);
127+
128+
$this->objectManager->setBackwardCompatibleProperty(
129+
$this->authentication,
130+
'customerAuthUpdate',
131+
$this->customerAuthUpdate
132+
);
113133
}
114134

115135
public function testProcessAuthenticationFailureLockingIsDisabled()
@@ -164,16 +184,10 @@ public function testProcessAuthenticationFailureFirstAttempt(
164184
->method('retrieveSecureData')
165185
->with($customerId)
166186
->willReturn($this->customerSecureMock);
167-
$customerMock = $this->getMockBuilder(CustomerInterface::class)
168-
->disableOriginalConstructor()
169-
->getMock();
170-
$this->customerRepositoryMock->expects($this->once())
171-
->method('getById')
187+
$this->customerAuthUpdate->expects($this->once())
188+
->method('saveAuth')
172189
->with($customerId)
173-
->willReturn($customerMock);
174-
$this->customerRepositoryMock->expects($this->once())
175-
->method('save')
176-
->with($customerMock);
190+
->willReturnSelf();
177191

178192
$this->customerSecureMock->expects($this->once())->method('getFailuresNum')->willReturn($failureNum);
179193
$this->customerSecureMock->expects($this->once())
@@ -210,16 +224,10 @@ public function testUnlock()
210224
->method('retrieveSecureData')
211225
->with($customerId)
212226
->willReturn($this->customerSecureMock);
213-
$customerMock = $this->getMockBuilder(CustomerInterface::class)
214-
->disableOriginalConstructor()
215-
->getMock();
216-
$this->customerRepositoryMock->expects($this->once())
217-
->method('getById')
227+
$this->customerAuthUpdate->expects($this->once())
228+
->method('saveAuth')
218229
->with($customerId)
219-
->willReturn($customerMock);
220-
$this->customerRepositoryMock->expects($this->once())
221-
->method('save')
222-
->with($customerMock);
230+
->willReturnSelf();
223231
$this->customerSecureMock->expects($this->once())->method('setFailuresNum')->with(0);
224232
$this->customerSecureMock->expects($this->once())->method('setFirstFailure')->with(null);
225233
$this->customerSecureMock->expects($this->once())->method('setLockExpires')->with(null);
@@ -312,9 +320,10 @@ public function testAuthenticate($result)
312320
->with($customerId)
313321
->willReturn($this->customerSecureMock);
314322

315-
$this->customerRepositoryMock->expects($this->once())
316-
->method('save')
317-
->willReturn($customerMock);
323+
$this->customerAuthUpdate->expects($this->once())
324+
->method('saveAuth')
325+
->with($customerId)
326+
->willReturnSelf();
318327

319328
$this->setExpectedException(\Magento\Framework\Exception\InvalidEmailOrPasswordException::class);
320329
$this->authentication->authenticate($customerId, $password);

0 commit comments

Comments
 (0)