Skip to content

Commit 8faadab

Browse files
committed
Make identifier parameter optional in AbstractAuthenticator
Default to null so authenticators that don't need an identifier (like SessionAuthenticator) can be constructed without arguments.
1 parent a3f120a commit 8faadab

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Authenticator/AbstractAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
5252
* @param \Authentication\Identifier\IdentifierInterface|null $identifier Identifier instance.
5353
* @param array<string, mixed> $config Configuration settings.
5454
*/
55-
public function __construct(?IdentifierInterface $identifier, array $config = [])
55+
public function __construct(?IdentifierInterface $identifier = null, array $config = [])
5656
{
5757
$this->_identifier = $identifier;
5858
$this->setConfig($config);

tests/TestCase/Authenticator/SessionAuthenticatorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testAuthenticateSuccess()
7474

7575
$request = $request->withAttribute('session', $this->sessionMock);
7676

77-
$authenticator = new SessionAuthenticator(null);
77+
$authenticator = new SessionAuthenticator();
7878
$result = $authenticator->authenticate($request);
7979

8080
$this->assertInstanceOf(Result::class, $result);
@@ -97,7 +97,7 @@ public function testAuthenticateFailure()
9797

9898
$request = $request->withAttribute('session', $this->sessionMock);
9999

100-
$authenticator = new SessionAuthenticator(null);
100+
$authenticator = new SessionAuthenticator();
101101
$result = $authenticator->authenticate($request);
102102

103103
$this->assertInstanceOf(Result::class, $result);
@@ -114,7 +114,7 @@ public function testPersistIdentity()
114114
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
115115
$request = $request->withAttribute('session', $this->sessionMock);
116116
$response = new Response();
117-
$authenticator = new SessionAuthenticator(null);
117+
$authenticator = new SessionAuthenticator();
118118

119119
$data = new ArrayObject(['username' => 'florian']);
120120

@@ -157,7 +157,7 @@ public function testClearIdentity()
157157
$request = $request->withAttribute('session', $this->sessionMock);
158158
$response = new Response();
159159

160-
$authenticator = new SessionAuthenticator(null);
160+
$authenticator = new SessionAuthenticator();
161161

162162
$this->sessionMock->expects($this->once())
163163
->method('delete')
@@ -186,7 +186,7 @@ public function testImpersonate()
186186
$request = $request->withAttribute('session', $this->sessionMock);
187187
$response = new Response();
188188

189-
$authenticator = new SessionAuthenticator(null);
189+
$authenticator = new SessionAuthenticator();
190190
$AuthUsers = TableRegistry::getTableLocator()->get('AuthUsers');
191191
$impersonator = $AuthUsers->newEntity([
192192
'username' => 'mariano',
@@ -225,7 +225,7 @@ public function testImpersonateAlreadyImpersonating()
225225
$request = $request->withAttribute('session', $this->sessionMock);
226226
$response = new Response();
227227

228-
$authenticator = new SessionAuthenticator(null);
228+
$authenticator = new SessionAuthenticator();
229229
$impersonator = new ArrayObject([
230230
'username' => 'mariano',
231231
'password' => 'password',
@@ -259,7 +259,7 @@ public function testStopImpersonating()
259259
$request = $request->withAttribute('session', $this->sessionMock);
260260
$response = new Response();
261261

262-
$authenticator = new SessionAuthenticator(null);
262+
$authenticator = new SessionAuthenticator();
263263

264264
$impersonator = new ArrayObject([
265265
'username' => 'mariano',
@@ -306,7 +306,7 @@ public function testStopImpersonatingNotImpersonating()
306306
$request = $request->withAttribute('session', $this->sessionMock);
307307
$response = new Response();
308308

309-
$authenticator = new SessionAuthenticator(null);
309+
$authenticator = new SessionAuthenticator();
310310

311311
$this->sessionMock->expects($this->once())
312312
->method('check')
@@ -343,7 +343,7 @@ public function testIsImpersonating()
343343
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
344344
$request = $request->withAttribute('session', $this->sessionMock);
345345

346-
$authenticator = new SessionAuthenticator(null);
346+
$authenticator = new SessionAuthenticator();
347347

348348
$this->sessionMock->expects($this->once())
349349
->method('check')

0 commit comments

Comments
 (0)