Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Support/Converters/Contracts/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public function description(): string;
public function optionsSchema(): array;

public function validateOptions(array $options): array;

public function isRecommended(): bool;
}
2 changes: 1 addition & 1 deletion app/Support/Converters/ConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function targetsFor(string $source): array
label: $converter->label(),
description: $converter->description(),
converterKey: $converter->key(),
recommended: false,
recommended: $converter->isRecommended(),
),
$this->forSource($source),
);
Expand Down
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/JpgToPdfConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/JpgToPngConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/JpgToWebpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/PngToJpgConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/PngToPdfConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions app/Support/Converters/Image/PngToWebpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions tests/Fakes/Converters/FakeJpgToWebpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function validateOptions(array $options): array
{
return $options;
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions tests/Fakes/Converters/FakePngToJpgConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function validateOptions(array $options): array
{
return $options;
}

public function isRecommended(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions tests/Fakes/Converters/FakePngToPdfConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function validateOptions(array $options): array
{
return $options;
}

public function isRecommended(): bool
{
return false;
}
}
37 changes: 37 additions & 0 deletions tests/Unit/Converters/RecommendedTargetMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use App\Support\Converters\ConverterRegistry;
use App\Support\Converters\Image\JpgToPdfConverter;
use App\Support\Converters\Image\JpgToPngConverter;
use App\Support\Converters\Image\JpgToWebpConverter;
use App\Support\Converters\Image\PngToJpgConverter;
use App\Support\Converters\Image\PngToPdfConverter;
use App\Support\Converters\Image\PngToWebpConverter;

function mvpRegistry(): ConverterRegistry
{
return new ConverterRegistry([
app(PngToJpgConverter::class),
app(PngToWebpConverter::class),
app(PngToPdfConverter::class),
app(JpgToPngConverter::class),
app(JpgToWebpConverter::class),
app(JpgToPdfConverter::class),
]);
}

it('marks one png target as recommended', function () {
$recommended = collect(mvpRegistry()->targetsFor('png'))
->filter(fn ($target) => $target->recommended === true);

expect($recommended)->toHaveCount(1);
expect($recommended->first()->format)->toBe('jpg');
});

it('marks one jpg target as recommended', function () {
$recommended = collect(mvpRegistry()->targetsFor('jpg'))
->filter(fn ($target) => $target->recommended === true);

expect($recommended)->toHaveCount(1);
expect($recommended->first()->format)->toBe('webp');
});