fix(banks:set-logo): add JPEG support test coverage and prompt for missing arguments (#214)

## 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
This commit is contained in:
Víctor Falcón 2026-03-07 16:33:54 +00:00 committed by GitHub
parent 2f1b9065f0
commit cbe28ff708
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 1 deletions

View File

@ -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<string, string|array<int, string>>
*/
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'));

View File

@ -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();
});