From 0698589d5b83c7dcfd1f668fdda890a49cd9bbfd Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Sat, 11 Apr 2026 12:39:35 +0200 Subject: [PATCH] Fix test bootstrap and ActorSyncer test doubles --- tests/Import/ActorSyncerTest.php | 55 ++++---------------------------- tests/bootstrap.php | 3 ++ 2 files changed, 9 insertions(+), 49 deletions(-) diff --git a/tests/Import/ActorSyncerTest.php b/tests/Import/ActorSyncerTest.php index 1f9f988..5bc24c5 100644 --- a/tests/Import/ActorSyncerTest.php +++ b/tests/Import/ActorSyncerTest.php @@ -12,7 +12,7 @@ use App\Gateway\TMDBGateway; use App\Import\ActorSyncer; use App\Model\TMDB\TMDBMovieCredit; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\Persistence\ObjectRepository; +use Doctrine\ORM\EntityRepository; use PHPUnit\Framework\TestCase; class ActorSyncerTest extends TestCase @@ -36,60 +36,17 @@ class ActorSyncerTest extends TestCase ]), ); - $actorRepository = new class implements ObjectRepository { - public function findAll(): array - { - return []; - } + $actorRepository = $this->createMock(EntityRepository::class); + $actorRepository->method('findOneBy')->willReturn(null); - public function findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null): array - { - return []; - } - - public function findOneBy(array $criteria): ?object - { - return null; - } - - public function getClassName(): string - { - return Actor::class; - } - }; - - $movieRoleRepository = new class implements ObjectRepository { - public function findAll(): array - { - return []; - } - - public function findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null): array - { - return []; - } - - public function findOneBy(array $criteria): ?object - { - return null; - } - - public function getClassName(): string - { - return MovieRole::class; - } - - public function count(array $criteria = []): int - { - return 0; - } - }; + $movieRoleRepository = $this->createMock(EntityRepository::class); + $movieRoleRepository->method('count')->willReturn(0); $persisted = []; $em = $this->createMock(EntityManagerInterface::class); $em->method('getRepository')->willReturnCallback( - static fn (string $class): ObjectRepository => match ($class) { + static fn (string $class): EntityRepository => match ($class) { Actor::class => $actorRepository, MovieRole::class => $movieRoleRepository, default => throw new \InvalidArgumentException("Unexpected repository for {$class}"), diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 47a5855..ac62806 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,6 +8,9 @@ if (method_exists(Dotenv::class, 'bootEnv')) { (new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); } +$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test'; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '1'; + if ($_SERVER['APP_DEBUG']) { umask(0000); }