Skip to content

Commit f341c88

Browse files
committed
Update test mock to support Auth.PasswordRehash.authenticators config
The _mockAuthentication method now mocks authenticators() in addition to identifiers() to support the new configuration format where the Password identifier is accessed through the Form authenticator.
1 parent af3431e commit f341c88

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/TestCase/Controller/Traits/BaseTrait.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ protected function _mockAuthentication($user = null, $failures = [], $identifier
263263
'getResult',
264264
'getFailures',
265265
'identifiers',
266+
'authenticators',
266267
])->getMock();
267268

268269
if ($user) {
@@ -286,6 +287,31 @@ protected function _mockAuthentication($user = null, $failures = [], $identifier
286287
->method('identifiers')
287288
->will($this->returnValue($identifiers));
288289

290+
// Mock authenticators() for Auth.PasswordRehash.authenticators config
291+
$formAuthenticator = $this->getMockBuilder(\Authentication\Authenticator\FormAuthenticator::class)
292+
->disableOriginalConstructor()
293+
->onlyMethods(['getIdentifier'])
294+
->getMock();
295+
$formAuthenticator->expects($this->any())
296+
->method('getIdentifier')
297+
->willReturn($identifiers);
298+
299+
$authenticators = $this->getMockBuilder(\Authentication\Authenticator\AuthenticatorCollection::class)
300+
->disableOriginalConstructor()
301+
->onlyMethods(['has', 'get'])
302+
->getMock();
303+
$authenticators->expects($this->any())
304+
->method('has')
305+
->willReturnCallback(fn($name) => $name === 'Form');
306+
$authenticators->expects($this->any())
307+
->method('get')
308+
->with('Form')
309+
->willReturn($formAuthenticator);
310+
311+
$authentication->expects($this->any())
312+
->method('authenticators')
313+
->willReturn($authenticators);
314+
289315
$this->Trait->setRequest($this->Trait->getRequest()->withAttribute('authentication', $authentication));
290316

291317
$controller = new Controller($this->Trait->getRequest());

0 commit comments

Comments
 (0)