getSeasonByCode('krtek'); $candidate = $this->getCandidateBySeasonAndName($krtekSeason, 'Tom'); $question = $this->questionRepository->findNextQuestionForCandidate($candidate); $this->assertInstanceOf(Question::class, $question); $answers = $question->answers; $this->assertGreaterThanOrEqual(2, $answers->count()); $firstAnswer = $answers->first(); $secondAnswer = $answers->get(1); $this->assertInstanceOf(Answer::class, $firstAnswer); $this->assertInstanceOf(Answer::class, $secondAnswer); $this->entityManager->persist(new GivenAnswer($candidate, $question->quiz, $firstAnswer)); $this->entityManager->flush(); $this->entityManager->persist(new GivenAnswer($candidate, $question->quiz, $secondAnswer)); $this->expectException(UniqueConstraintViolationException::class); $this->entityManager->flush(); } }