Merge pull request #144 from dantaspaulo/fix/media-services-null-key

fix(media): don't 500 when the Unsplash/Giphy key is set to null
This commit is contained in:
Paulo Castellano 2026-07-02 15:56:14 -03:00 committed by GitHub
commit 5ba6779c76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View file

@ -15,7 +15,7 @@ class GiphyService
public function __construct()
{
$this->apiKey = config('services.giphy.api_key', '');
$this->apiKey = (string) config('services.giphy.api_key', '');
}
/**

View file

@ -15,7 +15,7 @@ class UnsplashService
public function __construct()
{
$this->accessKey = config('services.unsplash.access_key', '');
$this->accessKey = (string) config('services.unsplash.access_key', '');
}
/**

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use App\Services\GiphyService;
use App\Services\UnsplashService;
test('unsplash service tolerates a null access key without throwing', function () {
config(['services.unsplash.access_key' => null]);
$result = (new UnsplashService)->search('cats');
expect($result)->toBe(['results' => [], 'total' => 0, 'total_pages' => 0]);
});
test('giphy service tolerates a null api key without throwing', function () {
config(['services.giphy.api_key' => null]);
$result = (new GiphyService)->search('cats');
expect($result)->toBe(['results' => [], 'total' => 0, 'total_pages' => 0]);
});