diff --git a/src/Bridges/CacheBridgeAbstract.php b/src/Bridges/CacheBridgeAbstract.php index 8f7e45b..e4c487d 100644 --- a/src/Bridges/CacheBridgeAbstract.php +++ b/src/Bridges/CacheBridgeAbstract.php @@ -118,7 +118,7 @@ final public function save(CacheItemInterface $item): bool return false; } - $value = serialize($item->get()); + $value = serialize($item->getRawValue()); $key = $item->getKey(); $expires = $item->getExpiration(); diff --git a/src/Events.php b/src/Events.php index df25d6c..e558c5d 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 292c847..559e0c7 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 ac3a41d..096373f 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 b88cc11..c2fd21b 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/Bridges/CacheBridgeTest.php b/tests/Unit/Bridges/CacheBridgeTest.php index 437de08..5820561 100644 --- a/tests/Unit/Bridges/CacheBridgeTest.php +++ b/tests/Unit/Bridges/CacheBridgeTest.php @@ -36,9 +36,7 @@ expect($cache) ->toBeInstanceOf(CacheItemBridge::class) ->isHit()->toBeTrue() - ->get()->toBeNull() - ->set(42) - ->get()->toBe(42); + ->get()->toEqual(42); $results = $pool->getItems(); @@ -46,12 +44,12 @@ ->toBeArray() ->toHaveCount(0); - $results = $pool->getItems(['testing' => uniqid()]); + $results = $pool->getItems(['testing']); expect($results['testing']) ->toBeInstanceOf(CacheItemBridge::class) ->isHit()->toBeTrue() - ->get()->not()->toBe(42); + ->get()->toEqual(42); $this->app[\Illuminate\Cache\CacheManager::class] ->getStore() diff --git a/tests/Unit/UserProviderTest.php b/tests/Unit/UserProviderTest.php index 9b0d909..60d12d1 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(); +});