From cbe28ff708a2f94df4f590d913f3f370514be9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Falc=C3=B3n?= Date: Sat, 7 Mar 2026 16:33:54 +0000 Subject: [PATCH] fix(banks:set-logo): add JPEG support test coverage and prompt for missing arguments (#214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Fixes `banks:set-logo` for JPEG images by adding a `makeJpeg()` test helper and a full JPEG test case — the pipeline was working but completely untested, meaning any regression would go undetected - Implements `PromptsForMissingInput` so the command interactively prompts for `bank` and `url` when they are not passed as arguments --- app/Console/Commands/SetBankLogoCommand.php | 16 +++++- .../Console/SetBankLogoCommandTest.php | 50 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/SetBankLogoCommand.php b/app/Console/Commands/SetBankLogoCommand.php index ecb87482..d25ab200 100644 --- a/app/Console/Commands/SetBankLogoCommand.php +++ b/app/Console/Commands/SetBankLogoCommand.php @@ -4,13 +4,14 @@ namespace App\Console\Commands; use App\Models\Bank; use Illuminate\Console\Command; +use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Http\Client\ConnectionException; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Storage; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\ImageManager; -class SetBankLogoCommand extends Command +class SetBankLogoCommand extends Command implements PromptsForMissingInput { protected $signature = 'banks:set-logo {bank : The UUID of the bank} @@ -18,6 +19,19 @@ class SetBankLogoCommand extends Command protected $description = 'Download an image from a URL, process it, and set it as the logo for a bank'; + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array> + */ + protected function promptForMissingArgumentsUsing(): array + { + return [ + 'bank' => ['Which bank UUID should the logo be set for?', 'E.g. 01234567-89ab-cdef-0123-456789abcdef'], + 'url' => ['What is the image URL to download?', 'E.g. https://example.com/logo.png'], + ]; + } + public function handle(): int { $bank = Bank::query()->find($this->argument('bank')); diff --git a/tests/Feature/Console/SetBankLogoCommandTest.php b/tests/Feature/Console/SetBankLogoCommandTest.php index 62359b0b..3d5ef7e8 100644 --- a/tests/Feature/Console/SetBankLogoCommandTest.php +++ b/tests/Feature/Console/SetBankLogoCommandTest.php @@ -17,6 +17,17 @@ function makePng(int $width, int $height): string return (string) $contents; } +function makeJpeg(int $width, int $height): string +{ + $im = imagecreatetruecolor($width, $height); + ob_start(); + imagejpeg($im); + $contents = ob_get_clean(); + imagedestroy($im); + + return (string) $contents; +} + test('downloads and stores a square image as the bank logo', function () { Storage::fake('public'); @@ -111,3 +122,42 @@ test('fails when downloaded content is not a valid image', function () { ->expectsOutputToContain('Downloaded file is not a valid image') ->assertFailed(); }); + +test('downloads and stores a square jpeg image as the bank logo', function () { + Storage::fake('public'); + + $bank = Bank::factory()->create(['logo' => null]); + $squareJpeg = makeJpeg(300, 300); + + Http::fake([ + 'https://example.test/logo.jpg' => Http::response($squareJpeg, 200, ['Content-Type' => 'image/jpeg']), + ]); + + artisan('banks:set-logo', ['bank' => $bank->id, 'url' => 'https://example.test/logo.jpg']) + ->expectsOutputToContain('Image downloaded (300×300px).') + ->expectsOutputToContain('Resized to 250×250px.') + ->expectsOutputToContain("Logo updated for \"{$bank->name}\".") + ->assertSuccessful(); + + Storage::disk('public')->assertExists("banks/logos/{$bank->id}.png"); + expect($bank->fresh()->logo)->not->toBeNull(); +}); + +test('prompts for bank uuid and url when no arguments are provided', function () { + Storage::fake('public'); + + $bank = Bank::factory()->create(['logo' => null]); + $squarePng = makePng(100, 100); + + Http::fake([ + 'https://example.test/logo.png' => Http::response($squarePng, 200, ['Content-Type' => 'image/png']), + ]); + + artisan('banks:set-logo') + ->expectsQuestion('Which bank UUID should the logo be set for?', $bank->id) + ->expectsQuestion('What is the image URL to download?', 'https://example.test/logo.png') + ->assertSuccessful(); + + Storage::disk('public')->assertExists("banks/logos/{$bank->id}.png"); + expect($bank->fresh()->logo)->not->toBeNull(); +});