PIMS/tests/Unit/Movies/ShowMovieServiceTest.php

52 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2025-12-07 03:49:26 +00:00
<?php
namespace Tests\Unit\Movies;
use App\Modules\Movies\Models\{Movie, Genre, Actor, Director, Studio, Country, Language};
use App\Modules\Movies\Services\Browse\ShowMovieService;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ShowMovieServiceTest extends TestCase
{
use RefreshDatabase;
public function test_returns_movie_with_relations(): void
{
$movie = Movie::factory()->create();
$genres = Genre::factory()->count(2)->create();
$actors = Actor::factory()->count(3)->create();
$directors = Director::factory()->count(1)->create();
$studios = Studio::factory()->count(2)->create();
$countries = Country::factory()->count(1)->create();
$languages = Language::factory()->count(1)->create();
$movie->genres()->sync($genres->pluck('id'));
$movie->actors()->sync($actors->pluck('id'));
$movie->directors()->sync($directors->pluck('id'));
$movie->studios()->sync($studios->pluck('id'));
$movie->countries()->sync($countries->pluck('id'));
$movie->languages()->sync($languages->pluck('id'));
$service = new ShowMovieService();
$fetched = $service->getById($movie->id);
$this->assertSame($movie->id, $fetched->id);
$this->assertCount(2, $fetched->genres);
$this->assertCount(3, $fetched->actors);
$this->assertCount(1, $fetched->directors);
$this->assertCount(2, $fetched->studios);
$this->assertCount(1, $fetched->countries);
$this->assertCount(1, $fetched->languages);
}
public function test_throws_on_missing(): void
{
$this->expectException(ModelNotFoundException::class);
$service = new ShowMovieService();
$service->getById(999);
}
}