From a53f05ce83f63262cde3cc774d33e0dce52fd850 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Thu, 7 Dec 2023 01:06:32 -0600 Subject: [PATCH] Resolve code coverage warnings --- src/Events.php | 2 ++ src/Guards/AuthenticationGuard.php | 2 ++ src/Guards/GuardAbstract.php | 5 +++++ src/UserProviderAbstract.php | 9 +++++++++ tests/Unit/UserProviderTest.php | 7 +++++++ 5 files changed, 25 insertions(+) diff --git a/src/Events.php b/src/Events.php index df25d6c0..e558c5d6 100644 --- a/src/Events.php +++ b/src/Events.php @@ -29,6 +29,8 @@ /** * @api + * + * @codeCoverageIgnore */ final class Events implements EventsContract { diff --git a/src/Guards/AuthenticationGuard.php b/src/Guards/AuthenticationGuard.php index 292c8475..559e0c70 100644 --- a/src/Guards/AuthenticationGuard.php +++ b/src/Guards/AuthenticationGuard.php @@ -280,6 +280,7 @@ public function user(): ?Authenticatable /** * @var ?Authenticatable $lastResponse */ + // @codeCoverageIgnoreStart if (class_exists('\Laravel\Telescope\Telescope')) { static $depth = 0; static $lastCalled = null; @@ -304,6 +305,7 @@ public function user(): ?Authenticatable ++$depth; $lastCalled = time(); } + // @codeCoverageIgnoreEnd $currentUser = $this->getCredential()?->getUser(); diff --git a/src/Guards/GuardAbstract.php b/src/Guards/GuardAbstract.php index ac3a41d4..096373f8 100644 --- a/src/Guards/GuardAbstract.php +++ b/src/Guards/GuardAbstract.php @@ -217,7 +217,9 @@ final public function processToken( Events::dispatch($event = new TokenVerificationFailed($token, $invalidTokenException)); if ($event->throwException) { + // @codeCoverageIgnoreStart throw $invalidTokenException; + // @codeCoverageIgnoreEnd } return null; @@ -242,6 +244,9 @@ final public function sdk( return $this->sdk->getSdk(); } + /** + * @codeCoverageIgnore + */ final public function service(): ?InstanceEntityContract { return $this->sdk; diff --git a/src/UserProviderAbstract.php b/src/UserProviderAbstract.php index b88cc11e..c2fd21be 100644 --- a/src/UserProviderAbstract.php +++ b/src/UserProviderAbstract.php @@ -60,6 +60,8 @@ final public function retrieveByCredentials(array $credentials): ?Authenticatabl static $lastResponse = null; static $lastCredentials = null; + // @codeCoverageIgnoreStart + /** * @var ?Authenticatable $lastResponse * @var array $lastCredentials @@ -94,6 +96,8 @@ final public function retrieveByCredentials(array $credentials): ?Authenticatabl $lastCredentials = $credentials; } + // @codeCoverageIgnoreEnd + $lastResponse = $this->getRepository()->fromSession($credentials); $this->withoutRecording(static fn (): bool => Cache::put('auth0_sdk_credential_lookup_' . $hash, $lastResponse, 5)); @@ -222,6 +226,11 @@ protected function setRepositoryName(string $repositoryName): void $this->repositoryName = $repositoryName; } + /** + * @codeCoverageIgnore + * + * @param callable $callback + */ protected function withoutRecording(callable $callback): mixed { if (class_exists(self::TELESCOPE)) { diff --git a/tests/Unit/UserProviderTest.php b/tests/Unit/UserProviderTest.php index 9b0d909c..60d12d15 100644 --- a/tests/Unit/UserProviderTest.php +++ b/tests/Unit/UserProviderTest.php @@ -157,3 +157,10 @@ expect($provider->getRepository()) ->toBeInstanceOf($repository::class); }); + +test('retrieveByCredentials() returns `null` when an empty array is provided', function (): void { + $provider = new UserProvider(['model' => uniqid()]); + $repository = new UserRepository(); + + expect($provider->retrieveByCredentials([]))->toBeNull(); +});