diff --git a/database/factories/MediaFactory.php b/database/factories/MediaFactory.php index 3994ca3..68c945d 100644 --- a/database/factories/MediaFactory.php +++ b/database/factories/MediaFactory.php @@ -3,7 +3,6 @@ namespace Finller\LaravelMedia\Database\Factories; use Finller\LaravelMedia\Casts\GeneratedConversion; -use Finller\LaravelMedia\Enums\GeneratedConversionState; use Finller\LaravelMedia\Enums\MediaType; use Finller\LaravelMedia\Media; use Illuminate\Database\Eloquent\Factories\Factory; @@ -28,7 +27,7 @@ public function definition() public static function generatedConversion() { return new GeneratedConversion( - state: GeneratedConversionState::Success, + state: 'success', type: MediaType::Image, file_name: 'poster.png', name: 'poster', @@ -36,7 +35,7 @@ public static function generatedConversion() disk: config('media.disk'), conversions: collect([ '480p' => new GeneratedConversion( - state: GeneratedConversionState::Success, + state: 'success', type: MediaType::Image, file_name: 'poster-480p.png', name: 'poster-480p', diff --git a/src/Casts/GeneratedConversion.php b/src/Casts/GeneratedConversion.php index 7fe6e9e..a7c33bf 100644 --- a/src/Casts/GeneratedConversion.php +++ b/src/Casts/GeneratedConversion.php @@ -2,7 +2,6 @@ namespace Finller\LaravelMedia\Casts; -use Finller\LaravelMedia\Enums\GeneratedConversionState; use Finller\LaravelMedia\Enums\MediaType; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Arr; @@ -26,7 +25,7 @@ public function __construct( public ?int $width = null, public ?float $aspect_ratio = null, public ?string $average_color = null, - public GeneratedConversionState $state = GeneratedConversionState::Pending, + public ?string $state = null, public Collection $conversions = new Collection() ) { } @@ -36,7 +35,7 @@ public static function make(array $attributes): self return new self( file_name: Arr::get($attributes, 'file_name'), name: Arr::get($attributes, 'name'), - state: GeneratedConversionState::from(Arr::get($attributes, 'state')), + state: Arr::get($attributes, 'state'), type: ($type = Arr::get($attributes, 'type')) ? MediaType::from($type) : MediaType::Other, disk: Arr::get($attributes, 'disk'), path: Arr::get($attributes, 'path'), diff --git a/src/Enums/GeneratedConversionState.php b/src/Enums/GeneratedConversionState.php deleted file mode 100644 index a39b480..0000000 --- a/src/Enums/GeneratedConversionState.php +++ /dev/null @@ -1,10 +0,0 @@ -generateBasePath($conversion)).$file_name, mime_type: $mime_type, type: $type, - state: GeneratedConversionState::Success, + state: 'success', disk: $this->disk, height: $dimension?->getHeight(), width: $dimension->getWidth(), diff --git a/tests/Feature/MediaTest.php b/tests/Feature/MediaTest.php index 3fb8291..2ea0b1a 100644 --- a/tests/Feature/MediaTest.php +++ b/tests/Feature/MediaTest.php @@ -3,13 +3,12 @@ use FFMpeg\Coordinate\Dimension; use Finller\LaravelMedia\Casts\GeneratedConversion; use Finller\LaravelMedia\Database\Factories\MediaFactory; -use Finller\LaravelMedia\Enums\GeneratedConversionState; use Finller\LaravelMedia\Enums\MediaType; use Finller\LaravelMedia\Media; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; -it('retrieve the correct generated conversion key', function () { +it('retrieve the generated conversion key', function () { /** @var Media $media */ $media = MediaFactory::new()->make(); @@ -18,7 +17,7 @@ expect($media->getConversionKey('poster.square.480p'))->toBe('poster.conversions.square.conversions.480p'); }); -it('retrieve the correct generated conversion', function () { +it('retrieve the generated conversion', function () { /** @var Media $media */ $media = MediaFactory::new()->make(); @@ -35,7 +34,7 @@ expect($media->getGeneratedConversion('poster.480p.foo'))->toBe(null); }); -it('retrieve the correct generated conversion path', function () { +it('retrieve the generated conversion path', function () { /** @var Media $media */ $media = MediaFactory::new()->make(); @@ -47,7 +46,7 @@ expect($media->getPath('poster.480p'))->toBe('/poster/conversions/480p/poster-480p.png'); }); -it('add the correct generated conversion', function () { +it('add the generated conversion', function () { /** @var Media $media */ $media = MediaFactory::new()->make(); @@ -59,7 +58,7 @@ $media->addGeneratedConversion('optimized', new GeneratedConversion( file_name: 'optimized.png', name: 'optimized', - state: GeneratedConversionState::Pending, + state: 'pending', path: '/optimized/optimized.png', type: MediaType::Image, disk: config('media.disk') @@ -68,7 +67,7 @@ $media->addGeneratedConversion('poster-optimized', new GeneratedConversion( file_name: 'poster-optimized.png', name: 'poster-optimized', - state: GeneratedConversionState::Pending, + state: 'pending', path: 'poster/conversions/optimized/poster-optimized.png', type: MediaType::Image, disk: config('media.disk') @@ -78,6 +77,17 @@ expect($media->hasGeneratedConversion('poster.poster-optimized'))->toBe(true); }); +it('update a conversion', function () { + /** @var Media $media */ + $media = MediaFactory::new()->make(); + + $media->generated_conversions = collect([ + 'poster' => MediaFactory::generatedConversion(), + ]); + + expect($media->getGeneratedConversion('poster')?->state)->tobe('success'); +}); + it('store an uploaded image', function () { /** @var Media $media */ $media = MediaFactory::new()->make();