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); } }