83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
use App\Entity\Actor;
|
|
use App\Entity\Movie;
|
|
use App\Entity\MovieRole;
|
|
use App\Entity\User;
|
|
use App\Entity\UserMovie;
|
|
use App\Repository\ActorRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
class ActorRepositoryTest extends KernelTestCase
|
|
{
|
|
private EntityManagerInterface $em;
|
|
private ActorRepository $repo;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->em = self::getContainer()->get(EntityManagerInterface::class);
|
|
$this->repo = self::getContainer()->get(ActorRepository::class);
|
|
}
|
|
|
|
public function testFindOneRandomInWatchedFilmsReturnsOnlyWatchedActors(): void
|
|
{
|
|
$user = new User();
|
|
$user->setEmail('test-watched-' . uniqid() . '@example.com');
|
|
$user->setPassword('test');
|
|
$this->em->persist($user);
|
|
|
|
$watchedActor = new Actor();
|
|
$watchedActor->setName('Watched Actor');
|
|
$watchedActor->setPopularity(10.0);
|
|
$this->em->persist($watchedActor);
|
|
|
|
$movie = new Movie();
|
|
$movie->setTmdbId(99990);
|
|
$movie->setLtbxdRef('watched-test');
|
|
$movie->setTitle('Watched Film');
|
|
$this->em->persist($movie);
|
|
|
|
$role = new MovieRole();
|
|
$role->setActor($watchedActor);
|
|
$role->setMovie($movie);
|
|
$role->setCharacter('Hero');
|
|
$this->em->persist($role);
|
|
|
|
$userMovie = new UserMovie();
|
|
$userMovie->setUser($user);
|
|
$userMovie->setMovie($movie);
|
|
$this->em->persist($userMovie);
|
|
|
|
$unwatchedActor = new Actor();
|
|
$unwatchedActor->setName('Unwatched Actor');
|
|
$unwatchedActor->setPopularity(10.0);
|
|
$this->em->persist($unwatchedActor);
|
|
|
|
$movie2 = new Movie();
|
|
$movie2->setTmdbId(99991);
|
|
$movie2->setLtbxdRef('unwatched-test');
|
|
$movie2->setTitle('Unwatched Film');
|
|
$this->em->persist($movie2);
|
|
|
|
$role2 = new MovieRole();
|
|
$role2->setActor($unwatchedActor);
|
|
$role2->setMovie($movie2);
|
|
$role2->setCharacter('Villain');
|
|
$this->em->persist($role2);
|
|
|
|
$this->em->flush();
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$result = $this->repo->findOneRandomInWatchedFilms($user, 0, 'w');
|
|
$this->assertNotNull($result);
|
|
$this->assertSame($watchedActor->getId(), $result->getId());
|
|
}
|
|
}
|
|
}
|