64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
use App\Entity\Actor;
|
|
use App\Entity\Award;
|
|
use App\Entity\AwardType;
|
|
use App\Repository\AwardRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
class AwardRepositoryTest extends KernelTestCase
|
|
{
|
|
private EntityManagerInterface $em;
|
|
private AwardRepository $repo;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->em = self::getContainer()->get(EntityManagerInterface::class);
|
|
$this->repo = self::getContainer()->get(AwardRepository::class);
|
|
}
|
|
|
|
public function testFindOneRandomByActorAndTypesFiltersCorrectly(): void
|
|
{
|
|
$actor = new Actor();
|
|
$actor->setName('Award Actor Test');
|
|
$this->em->persist($actor);
|
|
|
|
$oscarType = new AwardType();
|
|
$oscarType->setName('Oscar')->setPattern('oscar');
|
|
$this->em->persist($oscarType);
|
|
|
|
$globeType = new AwardType();
|
|
$globeType->setName('Golden Globe')->setPattern('globe');
|
|
$this->em->persist($globeType);
|
|
|
|
$oscar = new Award();
|
|
$oscar->setName('Best Actor Oscar');
|
|
$oscar->setActor($actor);
|
|
$oscar->setAwardType($oscarType);
|
|
$this->em->persist($oscar);
|
|
|
|
$globe = new Award();
|
|
$globe->setName('Best Actor Globe');
|
|
$globe->setActor($actor);
|
|
$globe->setAwardType($globeType);
|
|
$this->em->persist($globe);
|
|
|
|
$this->em->flush();
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$result = $this->repo->findOneRandomByActorAndTypes($actor->getId(), [$oscarType->getId()]);
|
|
$this->assertNotNull($result);
|
|
$this->assertSame('Best Actor Oscar', $result->getName());
|
|
}
|
|
|
|
$result = $this->repo->findOneRandomByActorAndTypes($actor->getId(), null);
|
|
$this->assertNotNull($result);
|
|
}
|
|
}
|