Files
newznab-tmux/tests/Unit/Services/MovieServiceTest.php
T
2026-04-02 12:26:27 +02:00

104 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Services;
use App\Services\MovieService;
use App\Services\TraktService;
use App\Services\TvProcessing\Providers\TraktProvider;
use Illuminate\Support\Facades\Cache;
use PHPUnit\Framework\Attributes\Test;
use Tests\Unit\ImdbScraperTestCase;
class MovieServiceTest extends ImdbScraperTestCase
{
#[Test]
public function it_accepts_numeric_trakt_years_when_matching_movie_metadata(): void
{
Cache::flush();
$service = $this->makeMovieServiceForTraktResponse([
'title' => 'Example Movie',
'year' => 2024,
'ids' => ['trakt' => 12345],
'overview' => 'Test overview',
'tagline' => 'Test tagline',
'genres' => ['Drama'],
'rating' => 7.5,
'votes' => 10,
'language' => 'en',
'runtime' => 100,
'trailer' => '',
]);
$this->setMovieServiceProperty($service, 'currentTitle', 'Example Movie');
$this->setMovieServiceProperty($service, 'currentYear', '2024');
$movie = $service->fetchTraktTVProperties('8169446');
$this->assertIsArray($movie);
$this->assertSame('Example Movie', $movie['title']);
$this->assertSame(2024, $movie['year']);
}
#[Test]
public function it_still_rejects_mismatched_numeric_trakt_years(): void
{
Cache::flush();
$service = $this->makeMovieServiceForTraktResponse([
'title' => 'Example Movie',
'year' => 2024,
'ids' => ['trakt' => 12345],
]);
$this->setMovieServiceProperty($service, 'currentTitle', 'Example Movie');
$this->setMovieServiceProperty($service, 'currentYear', '2023');
$this->assertFalse($service->fetchTraktTVProperties('8169447'));
}
/**
* @param array<string, mixed> $response
*/
private function makeMovieServiceForTraktResponse(array $response): MovieService
{
$client = new class($response) extends TraktService
{
/**
* @param array<string, mixed> $response
*/
public function __construct(private array $response)
{
parent::__construct('test_trakt_key');
}
/**
* @return array<string, mixed>|null
*/
public function getMovieSummary(string $movie, string $extended = 'min'): ?array
{
return $this->response;
}
};
$provider = new TraktProvider;
$provider->client = $client;
$service = new MovieService;
$service->traktTv = $provider;
$service->echooutput = false;
$this->setMovieServiceProperty($service, 'traktcheck', 'test-key');
return $service;
}
private function setMovieServiceProperty(MovieService $service, string $property, mixed $value): void
{
$reflectionProperty = new \ReflectionProperty($service, $property);
$reflectionProperty->setValue($service, $value);
}
}