From 147356bff006a72627e6011f45bb96b79df062fb Mon Sep 17 00:00:00 2001 From: npwvestjens Date: Mon, 18 Aug 2025 09:44:39 +0200 Subject: [PATCH] Fix guard name implitic null issue --- .../Laravel/InteractsWithAuthentication.php | 16 ++++++++-------- .../Module/Laravel/InteractsWithConsole.php | 2 +- .../Module/Laravel/InteractsWithViews.php | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Codeception/Module/Laravel/InteractsWithAuthentication.php b/src/Codeception/Module/Laravel/InteractsWithAuthentication.php index 65d5e6f..70c965e 100644 --- a/src/Codeception/Module/Laravel/InteractsWithAuthentication.php +++ b/src/Codeception/Module/Laravel/InteractsWithAuthentication.php @@ -18,7 +18,7 @@ trait InteractsWithAuthentication * $I->amActingAs($user); * ``` */ - public function amActingAs(Authenticatable $user, string $guardName = null): void + public function amActingAs(Authenticatable $user, ?string $guardName = null): void { if (property_exists($user, 'wasRecentlyCreated') && $user->wasRecentlyCreated) { $user->wasRecentlyCreated = false; @@ -47,7 +47,7 @@ public function amActingAs(Authenticatable $user, string $guardName = null): voi * @param Authenticatable|array $user * @param string|null $guardName */ - public function amLoggedAs($user, string $guardName = null): void + public function amLoggedAs($user, ?string $guardName = null): void { if ($user instanceof Authenticatable) { $this->getAuth()->login($user); @@ -69,7 +69,7 @@ public function amLoggedAs($user, string $guardName = null): void * $I->assertAuthenticatedAs($user); * ``` */ - public function assertAuthenticatedAs(Authenticatable $user, string $guardName = null): void + public function assertAuthenticatedAs(Authenticatable $user, ?string $guardName = null): void { $expected = $this->getAuth()->guard($guardName)->user(); @@ -97,7 +97,7 @@ public function assertAuthenticatedAs(Authenticatable $user, string $guardName = * ]); * ``` */ - public function assertCredentials(array $credentials, string $guardName = null): void + public function assertCredentials(array $credentials, ?string $guardName = null): void { $this->assertTrue( $this->hasCredentials($credentials, $guardName), 'The given credentials are invalid.' @@ -115,7 +115,7 @@ public function assertCredentials(array $credentials, string $guardName = null): * ]); * ``` */ - public function assertInvalidCredentials(array $credentials, string $guardName = null): void + public function assertInvalidCredentials(array $credentials, ?string $guardName = null): void { $this->assertFalse( $this->hasCredentials($credentials, $guardName), 'The given credentials are valid.' @@ -130,7 +130,7 @@ public function assertInvalidCredentials(array $credentials, string $guardName = * $I->dontSeeAuthentication(); * ``` */ - public function dontSeeAuthentication(string $guardName = null): void + public function dontSeeAuthentication(?string $guardName = null): void { $this->assertFalse($this->isAuthenticated($guardName), 'The user is authenticated'); } @@ -156,7 +156,7 @@ public function logout(): void * $I->seeAuthentication(); * ``` */ - public function seeAuthentication(string $guardName = null): void + public function seeAuthentication(?string $guardName = null): void { $this->assertTrue($this->isAuthenticated($guardName), 'The user is not authenticated'); } @@ -164,7 +164,7 @@ public function seeAuthentication(string $guardName = null): void /** * Return true if the credentials are valid, false otherwise. */ - protected function hasCredentials(array $credentials, string $guardName = null): bool + protected function hasCredentials(array $credentials, ?string $guardName = null): bool { /** @var GuardHelpers $guard */ $guard = $this->getAuth()->guard($guardName); diff --git a/src/Codeception/Module/Laravel/InteractsWithConsole.php b/src/Codeception/Module/Laravel/InteractsWithConsole.php index 85a3ed1..a109994 100644 --- a/src/Codeception/Module/Laravel/InteractsWithConsole.php +++ b/src/Codeception/Module/Laravel/InteractsWithConsole.php @@ -21,7 +21,7 @@ trait InteractsWithConsole * * @return string|void */ - public function callArtisan(string $command, array $parameters = [], OutputInterface $output = null) + public function callArtisan(string $command, array $parameters = [], ?OutputInterface $output = null) { $console = $this->getConsoleKernel(); if (!$output) { diff --git a/src/Codeception/Module/Laravel/InteractsWithViews.php b/src/Codeception/Module/Laravel/InteractsWithViews.php index 5b42098..9dd70bb 100644 --- a/src/Codeception/Module/Laravel/InteractsWithViews.php +++ b/src/Codeception/Module/Laravel/InteractsWithViews.php @@ -43,7 +43,7 @@ public function dontSeeFormErrors(): void * $I->seeFormErrorMessage('username', 'Invalid Username'); * ``` */ - public function seeFormErrorMessage(string $field, string $errorMessage = null): void + public function seeFormErrorMessage(string $field, ?string $errorMessage = null): void { $viewErrorBag = $this->getViewErrorBag();