Skip to content

Commit

Permalink
remove state enum
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Nov 25, 2023
1 parent 7517ef9 commit 23cae7c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
5 changes: 2 additions & 3 deletions database/factories/MediaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,15 +27,15 @@ public function definition()
public static function generatedConversion()
{
return new GeneratedConversion(
state: GeneratedConversionState::Success,
state: 'success',
type: MediaType::Image,
file_name: 'poster.png',
name: 'poster',
path: '/poster/poster.png',
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',
Expand Down
5 changes: 2 additions & 3 deletions src/Casts/GeneratedConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
) {
}
Expand All @@ -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'),
Expand Down
10 changes: 0 additions & 10 deletions src/Enums/GeneratedConversionState.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Finller\LaravelMedia\Casts\GeneratedConversion;
use Finller\LaravelMedia\Casts\GeneratedConversions;
use Finller\LaravelMedia\Enums\GeneratedConversionState;
use Finller\LaravelMedia\Enums\MediaType;
use Finller\LaravelMedia\Helpers\File;
use Finller\LaravelMedia\Traits\HasUuid;
Expand Down Expand Up @@ -208,7 +207,7 @@ public function storeConversion(
path: ($basePath ?? $this->generateBasePath($conversion)).$file_name,
mime_type: $mime_type,
type: $type,
state: GeneratedConversionState::Success,
state: 'success',
disk: $this->disk,
height: $dimension?->getHeight(),
width: $dimension->getWidth(),
Expand Down
24 changes: 17 additions & 7 deletions tests/Feature/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

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

Expand All @@ -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();
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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();
Expand Down

0 comments on commit 23cae7c

Please sign in to comment.