Skip to content

Commit

Permalink
add medialibrary for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Jun 14, 2024
1 parent edc675d commit bd80a83
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@
"spatie/laravel-package-tools": "^1.16.3"
},
"require-dev": {
"larastan/larastan": "^2.8.0",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^8.0",
"larastan/larastan": "^2.8.0",
"orchestra/testbench": "^9.0",
"pestphp/pest": "^2.8.1",
"pestphp/pest-plugin-laravel": "*",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"spatie/laravel-medialibrary": "^11.6",
"spatie/laravel-ray": "^1.26",
"vlucas/phpdotenv": "^5.5"
},
Expand Down
15 changes: 14 additions & 1 deletion tests/Data/Models/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Image\Enums\Fit;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Movie extends Model
class Movie extends Model implements HasMedia
{
use HasFactory;
use HasUlids;
use InteractsWithMedia;

protected $fillable = [
'title',
Expand Down Expand Up @@ -59,6 +64,14 @@ class Movie extends Model

protected $queryPagination = 50;

public function registerMediaConversions(?Media $media = null): void
{
$this
->addMediaConversion('preview')
->fit(Fit::Contain, 300, 300)
->nonQueued();
}

public function similars(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Movie::class, 'similars', 'movie_id', 'similar_id');
Expand Down
21 changes: 21 additions & 0 deletions tests/Data/database/migrations/create_models_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,27 @@ public function up(): void

$table->timestamps();
});

Schema::create('media', function (Blueprint $table) {
$table->id();

$table->morphs('model');
$table->uuid()->nullable()->unique();
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
$table->string('mime_type')->nullable();
$table->string('disk');
$table->string('conversions_disk')->nullable();
$table->unsignedBigInteger('size');
$table->json('manipulations');
$table->json('custom_properties');
$table->json('generated_conversions');
$table->json('responsive_images');
$table->unsignedInteger('order_column')->nullable()->index();

$table->nullableTimestamps();
});
}

private function createTable(string $name): string
Expand Down

0 comments on commit bd80a83

Please sign in to comment.