diff --git a/app/Services/GiphyService.php b/app/Services/GiphyService.php index e60ff667..f5e674d4 100644 --- a/app/Services/GiphyService.php +++ b/app/Services/GiphyService.php @@ -15,7 +15,7 @@ class GiphyService public function __construct() { - $this->apiKey = config('services.giphy.api_key', ''); + $this->apiKey = (string) config('services.giphy.api_key', ''); } /** diff --git a/app/Services/UnsplashService.php b/app/Services/UnsplashService.php index 5ac1ad9a..db16237e 100644 --- a/app/Services/UnsplashService.php +++ b/app/Services/UnsplashService.php @@ -15,7 +15,7 @@ class UnsplashService public function __construct() { - $this->accessKey = config('services.unsplash.access_key', ''); + $this->accessKey = (string) config('services.unsplash.access_key', ''); } /** diff --git a/tests/Unit/Services/MediaSearchKeyFallbackTest.php b/tests/Unit/Services/MediaSearchKeyFallbackTest.php new file mode 100644 index 00000000..6fa85c47 --- /dev/null +++ b/tests/Unit/Services/MediaSearchKeyFallbackTest.php @@ -0,0 +1,22 @@ + 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]); +});