More tests!

This commit is contained in:
2025-10-31 22:00:28 +01:00
parent e41bedce8d
commit f886f0f6c2
13 changed files with 230 additions and 44 deletions

View File

@@ -0,0 +1,5 @@
when@test:
dama_doctrine_test:
enable_static_connection: true
enable_static_meta_data_cache: true
enable_static_query_cache: true

View File

@@ -26,7 +26,6 @@ return RectorConfig::configure()
privatization: true, privatization: true,
instanceOf: true, instanceOf: true,
earlyReturn: true, earlyReturn: true,
strictBooleans: true,
rectorPreset: true, rectorPreset: true,
phpunitCodeQuality: true, phpunitCodeQuality: true,
doctrineCodeQuality: true, doctrineCodeQuality: true,

View File

@@ -9,6 +9,7 @@ use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Tvdt\Entity\Season;
use Tvdt\Repository\SeasonRepository; use Tvdt\Repository\SeasonRepository;
use Tvdt\Repository\UserRepository; use Tvdt\Repository\UserRepository;
@@ -29,7 +30,7 @@ final readonly class ClaimSeasonCommand
): int { ): int {
try { try {
$season = $this->seasonRepository->findOneBySeasonCode($seasonCode); $season = $this->seasonRepository->findOneBySeasonCode($seasonCode);
if (null === $season) { if (!$season instanceof Season) {
throw new \InvalidArgumentException('Season not found'); throw new \InvalidArgumentException('Season not found');
} }

View File

@@ -13,7 +13,7 @@ use Tvdt\Entity\User;
final class TestFixtures extends Fixture implements FixtureGroupInterface final class TestFixtures extends Fixture implements FixtureGroupInterface
{ {
public function __construct( public function __construct(
private UserPasswordHasherInterface $passwordHasher, private readonly UserPasswordHasherInterface $passwordHasher,
) {} ) {}
public static function getGroups(): array public static function getGroups(): array

View File

@@ -7,10 +7,7 @@ namespace Tvdt\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Tvdt\Entity\Elimination;
use Tvdt\Entity\GivenAnswer;
use Tvdt\Entity\Quiz; use Tvdt\Entity\Quiz;
use Tvdt\Entity\QuizCandidate;
use Tvdt\Exception\ErrorClearingQuizException; use Tvdt\Exception\ErrorClearingQuizException;
/** /**
@@ -29,22 +26,26 @@ class QuizRepository extends ServiceEntityRepository
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$em->beginTransaction(); $em->beginTransaction();
try { try {
$em->createQueryBuilder() $em->createQuery(<<<DQL
->delete()->from(QuizCandidate::class, 'qc') delete from Tvdt\Entity\QuizCandidate qc
->where('qc.quiz = :quiz') where qc.quiz = :quiz
DQL)
->setParameter('quiz', $quiz) ->setParameter('quiz', $quiz)
->getQuery()->execute(); ->execute();
$em->createQueryBuilder() $em->createQuery(<<<DQL
->delete()->from(GivenAnswer::class, 'ga') delete from Tvdt\Entity\GivenAnswer ga
->where('ga.quiz = :quiz') where ga.quiz = :quiz
DQL)
->setParameter('quiz', $quiz) ->setParameter('quiz', $quiz)
->getQuery()->execute(); ->execute();
$em->createQueryBuilder()
->delete()->from(Elimination::class, 'e') $em->createQuery(<<<DQL
->where('e.quiz = :quiz') delete from Tvdt\Entity\Elimination e
where e.quiz = :quiz
DQL)
->setParameter('quiz', $quiz) ->setParameter('quiz', $quiz)
->getQuery()->execute(); ->execute();
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$this->logger->error($throwable->getMessage()); $this->logger->error($throwable->getMessage());
$em->rollback(); $em->rollback();

View File

@@ -25,7 +25,7 @@ class SeasonRepository extends ServiceEntityRepository
select s from Tvdt\Entity\Season s select s from Tvdt\Entity\Season s
where s.seasonCode = :seasonCode where s.seasonCode = :seasonCode
DQL) DQL)
->setParameter(':seasonCode', $seasonCode) ->setParameter('seasonCode', $seasonCode)
->setMaxResults(1) ->setMaxResults(1)
->getOneOrNullResult(); ->getOneOrNullResult();
} }

View File

@@ -4,24 +4,28 @@ declare(strict_types=1);
namespace Tvdt\Tests\Command; namespace Tvdt\Tests\Command;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
use Tvdt\Command\ClaimSeasonCommand;
use Tvdt\Entity\Season; use Tvdt\Entity\Season;
use Tvdt\Repository\SeasonRepository; use Tvdt\Repository\SeasonRepository;
#[CoversClass(ClaimSeasonCommand::class)]
final class ClaimSeasonCommandTest extends KernelTestCase final class ClaimSeasonCommandTest extends KernelTestCase
{ {
private SeasonRepository $seasonRepository; private SeasonRepository $seasonRepository;
private CommandTester $commandTester; private CommandTester $commandTester;
protected function setUp(): void protected function setUp(): void
{ {
$container = self::getContainer(); $container = self::getContainer();
\assert(self::$kernel instanceof KernelInterface); $this->assertInstanceOf(KernelInterface::class, self::$kernel);
$this->seasonRepository = $container->get(SeasonRepository::class); $this->seasonRepository = $container->get(SeasonRepository::class);
$application = new Application(self::$kernel); $application = new Application(self::$kernel);
@@ -37,13 +41,13 @@ final class ClaimSeasonCommandTest extends KernelTestCase
]); ]);
$season = $this->seasonRepository->findOneBySeasonCode('krtek'); $season = $this->seasonRepository->findOneBySeasonCode('krtek');
\assert($season instanceof Season); $this->assertInstanceOf(Season::class, $season);
$this->assertSame(Command::SUCCESS, $this->commandTester->getStatusCode()); $this->assertSame(Command::SUCCESS, $this->commandTester->getStatusCode());
$this->assertCount(1, $season->owners); $this->assertCount(1, $season->owners);
} }
public function testInvalidEmalFails(): void public function testInvalidEmailFails(): void
{ {
$this->commandTester->execute([ $this->commandTester->execute([
'season-code' => 'krtek', 'season-code' => 'krtek',
@@ -51,7 +55,6 @@ final class ClaimSeasonCommandTest extends KernelTestCase
]); ]);
$this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode()); $this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode());
$this->commandTester->getStatusCode();
} }
public function testInvalidSeasonCodeFails(): void public function testInvalidSeasonCodeFails(): void
@@ -62,6 +65,5 @@ final class ClaimSeasonCommandTest extends KernelTestCase
]); ]);
$this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode()); $this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode());
$this->commandTester->getStatusCode();
} }
} }

View File

@@ -4,24 +4,28 @@ declare(strict_types=1);
namespace Tvdt\Tests\Command; namespace Tvdt\Tests\Command;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
use Tvdt\Command\MakeAdminCommand;
use Tvdt\Entity\User; use Tvdt\Entity\User;
use Tvdt\Repository\UserRepository; use Tvdt\Repository\UserRepository;
#[CoversClass(MakeAdminCommand::class)]
final class MakeAdminCommandTest extends KernelTestCase final class MakeAdminCommandTest extends KernelTestCase
{ {
private UserRepository $userRepository; private UserRepository $userRepository;
private CommandTester $commandTester; private CommandTester $commandTester;
protected function setUp(): void protected function setUp(): void
{ {
$container = self::getContainer(); $container = self::getContainer();
\assert(self::$kernel instanceof KernelInterface); $this->assertInstanceOf(KernelInterface::class, self::$kernel);
$this->userRepository = $container->get(UserRepository::class); $this->userRepository = $container->get(UserRepository::class);
$application = new Application(self::$kernel); $application = new Application(self::$kernel);
@@ -36,19 +40,18 @@ final class MakeAdminCommandTest extends KernelTestCase
]); ]);
$user = $this->userRepository->findOneBy(['email' => 'test@example.org']); $user = $this->userRepository->findOneBy(['email' => 'test@example.org']);
\assert($user instanceof User); $this->assertInstanceOf(User::class, $user);
$this->assertSame(Command::SUCCESS, $this->commandTester->getStatusCode()); $this->assertSame(Command::SUCCESS, $this->commandTester->getStatusCode());
$this->assertContains('ROLE_ADMIN', $user->roles); $this->assertContains('ROLE_ADMIN', $user->roles);
} }
public function testInvalidEmalFails(): void public function testInvalidEmailFails(): void
{ {
$this->commandTester->execute([ $this->commandTester->execute([
'email' => 'nonexisting@example.org', 'email' => 'nonexisting@example.org',
]); ]);
$this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode()); $this->assertSame(Command::FAILURE, $this->commandTester->getStatusCode());
$this->commandTester->getStatusCode();
} }
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tvdt\Tests\Repository; namespace Tvdt\Tests\Repository;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tvdt\Entity\Candidate; use Tvdt\Entity\Candidate;
@@ -11,9 +12,11 @@ use Tvdt\Entity\Season;
use Tvdt\Repository\CandidateRepository; use Tvdt\Repository\CandidateRepository;
use Tvdt\Repository\SeasonRepository; use Tvdt\Repository\SeasonRepository;
class CandidateRepositoryTest extends KernelTestCase #[CoversClass(CandidateRepository::class)]
final class CandidateRepositoryTest extends KernelTestCase
{ {
private SeasonRepository $seasonRepository; private SeasonRepository $seasonRepository;
private CandidateRepository $candidateRepository; private CandidateRepository $candidateRepository;
protected function setUp(): void protected function setUp(): void
@@ -53,7 +56,7 @@ class CandidateRepositoryTest extends KernelTestCase
$krtekSeason, $krtekSeason,
'TWFyaWpu', 'TWFyaWpu',
); );
$this->assertNull($result); $this->assertNotInstanceOf(Candidate::class, $result);
} }
public function testGetCandidateByHashInvalidBase64HashReturnsNull(): void public function testGetCandidateByHashInvalidBase64HashReturnsNull(): void
@@ -64,7 +67,7 @@ class CandidateRepositoryTest extends KernelTestCase
$krtekSeason, $krtekSeason,
'TWFyaWpu*', 'TWFyaWpu*',
); );
$this->assertNull($result); $this->assertNotInstanceOf(Candidate::class, $result);
} }
public function testGetScores(): void public function testGetScores(): void

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Tvdt\Tests\Repository; namespace Tvdt\Tests\Repository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tvdt\Entity\Answer; use Tvdt\Entity\Answer;
use Tvdt\Entity\Candidate; use Tvdt\Entity\Candidate;
@@ -16,11 +17,15 @@ use Tvdt\Repository\CandidateRepository;
use Tvdt\Repository\QuestionRepository; use Tvdt\Repository\QuestionRepository;
use Tvdt\Repository\SeasonRepository; use Tvdt\Repository\SeasonRepository;
class QuestionRepositoryTest extends KernelTestCase #[CoversClass(QuestionRepository::class)]
final class QuestionRepositoryTest extends KernelTestCase
{ {
private EntityManagerInterface $entityManager; private EntityManagerInterface $entityManager;
private QuestionRepository $questionRepository; private QuestionRepository $questionRepository;
private SeasonRepository $seasonRepository; private SeasonRepository $seasonRepository;
private CandidateRepository $candidateRepository; private CandidateRepository $candidateRepository;
protected function setUp(): void protected function setUp(): void
@@ -36,9 +41,9 @@ class QuestionRepositoryTest extends KernelTestCase
public function testFindNextQuestionReturnsRightQuestion(): void public function testFindNextQuestionReturnsRightQuestion(): void
{ {
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek'); $krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
\assert($krtekSeason instanceof Season); $this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']); $candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']);
\assert($candidate instanceof Candidate); $this->assertInstanceOf(Candidate::class, $candidate);
$question = $this->questionRepository->findNextQuestionForCandidate($candidate); $question = $this->questionRepository->findNextQuestionForCandidate($candidate);
$this->assertInstanceOf(Question::class, $question); $this->assertInstanceOf(Question::class, $question);
@@ -55,7 +60,7 @@ class QuestionRepositoryTest extends KernelTestCase
$this->assertSame('Hoeveel broers heeft de Krtek?', $question->question, 'Getting question a second time fails'); $this->assertSame('Hoeveel broers heeft de Krtek?', $question->question, 'Getting question a second time fails');
$quiz = $krtekSeason->quizzes->last(); $quiz = $krtekSeason->quizzes->last();
\assert($quiz instanceof Quiz); $this->assertInstanceOf(Quiz::class, $quiz);
$krtekSeason->activeQuiz = $quiz; $krtekSeason->activeQuiz = $quiz;
$this->entityManager->flush(); $this->entityManager->flush();
@@ -64,42 +69,43 @@ class QuestionRepositoryTest extends KernelTestCase
$this->assertSame('Is de Krtek een man of een vrouw?', $question->question, 'Wrong question after switching season.'); $this->assertSame('Is de Krtek een man of een vrouw?', $question->question, 'Wrong question after switching season.');
} }
public function testFindNextQuestionGivesNullWhenAllQuestionsAnswred(): void public function testFindNextQuestionGivesNullWhenAllQuestionsAnswered(): void
{ {
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek'); $krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
\assert($krtekSeason instanceof Season); $this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']); $candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']);
\assert($candidate instanceof Candidate); $this->assertInstanceOf(Candidate::class, $candidate);
for ($i = 0; $i < 15; ++$i) { for ($i = 0; $i < 15; ++$i) {
$question = $this->questionRepository->findNextQuestionForCandidate($candidate); $question = $this->questionRepository->findNextQuestionForCandidate($candidate);
\assert($question instanceof Question); $this->assertInstanceOf(Question::class, $question);
$this->answerQuestion($question, $candidate); $this->answerQuestion($question, $candidate);
} }
$question = $this->questionRepository->findNextQuestionForCandidate($candidate); $question = $this->questionRepository->findNextQuestionForCandidate($candidate);
$this->assertNull($question); $this->assertNotInstanceOf(Question::class, $question);
} }
public function testFindNextQuestionWithNoActiveQuizReturnsNull(): void public function testFindNextQuestionWithNoActiveQuizReturnsNull(): void
{ {
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek'); $krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
\assert($krtekSeason instanceof Season); $this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']); $candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Tom']);
\assert($candidate instanceof Candidate); $this->assertInstanceOf(Candidate::class, $candidate);
$krtekSeason->activeQuiz = null; $krtekSeason->activeQuiz = null;
$this->entityManager->flush(); $this->entityManager->flush();
$question = $this->questionRepository->findNextQuestionForCandidate($candidate); $question = $this->questionRepository->findNextQuestionForCandidate($candidate);
$this->assertNull($question); $this->assertNotInstanceOf(Question::class, $question);
} }
private function answerQuestion(Question $question, Candidate $candidate): void private function answerQuestion(Question $question, Candidate $candidate): void
{ {
$answer = $question->answers->first(); $answer = $question->answers->first();
\assert($answer instanceof Answer); $this->assertInstanceOf(Answer::class, $answer);
$this->entityManager->persist(new GivenAnswer( $this->entityManager->persist(new GivenAnswer(
$candidate, $candidate,
$question->quiz, $question->quiz,

View File

@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace Tvdt\Tests\Repository;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tvdt\Entity\Candidate;
use Tvdt\Entity\Quiz;
use Tvdt\Entity\QuizCandidate;
use Tvdt\Entity\Season;
use Tvdt\Repository\CandidateRepository;
use Tvdt\Repository\QuizCandidateRepository;
use Tvdt\Repository\SeasonRepository;
#[CoversClass(QuizCandidateRepository::class)]
final class QuizCandidateRepositoryTest extends KernelTestCase
{
private SeasonRepository $seasonRepository;
private QuizCandidateRepository $quizCandidateRepository;
private CandidateRepository $candidateRepository;
protected function setUp(): void
{
$container = self::getContainer();
$this->seasonRepository = $container->get(SeasonRepository::class);
$this->quizCandidateRepository = $container->get(QuizCandidateRepository::class);
$this->candidateRepository = $container->get(CandidateRepository::class);
}
public function testCreateIfNotExists(): void
{
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
$this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Myrthe']);
$this->assertInstanceOf(Candidate::class, $candidate);
$quiz = $krtekSeason->activeQuiz;
$this->assertInstanceOf(Quiz::class, $quiz);
$result = $this->quizCandidateRepository->createIfNotExist($quiz, $candidate);
$this->assertTrue($result);
$quizCandidate = $this->quizCandidateRepository->findOneBy([
'candidate' => $candidate,
'quiz' => $quiz,
]);
$this->assertInstanceOf(QuizCandidate::class, $quizCandidate);
$result = $this->quizCandidateRepository->createIfNotExist($quiz, $candidate);
$this->assertFalse($result);
}
public function testSetCorrectionsForCandidateUpdatesCandidateCorrectly(): void
{
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
$this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Myrthe']);
$this->assertInstanceOf(Candidate::class, $candidate);
$quiz = $krtekSeason->activeQuiz;
$this->assertInstanceOf(Quiz::class, $quiz);
$this->quizCandidateRepository->createIfNotExist($quiz, $candidate);
$this->quizCandidateRepository->setCorrectionsForCandidate(
$quiz, $candidate, 3.5,
);
$quizCandidate = $this->quizCandidateRepository->findOneBy([
'candidate' => $candidate,
'quiz' => $quiz,
]);
$this->assertInstanceOf(QuizCandidate::class, $quizCandidate);
$this->assertEqualsWithDelta(3.5, $quizCandidate->corrections, 0.1);
}
public function testCannotGiveCorrectionsToCandidateWithoutResult(): void
{
$krtekSeason = $this->seasonRepository->findOneBySeasonCode('krtek');
$this->assertInstanceOf(Season::class, $krtekSeason);
$candidate = $this->candidateRepository->findOneBy(['season' => $krtekSeason, 'name' => 'Myrthe']);
$this->assertInstanceOf(Candidate::class, $candidate);
$quiz = $krtekSeason->activeQuiz;
$this->assertInstanceOf(Quiz::class, $quiz);
$this->expectException(\InvalidArgumentException::class);
$this->quizCandidateRepository->setCorrectionsForCandidate(
$quiz, $candidate, 3.5,
);
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Tvdt\Tests\Repository;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tvdt\Entity\Quiz;
use Tvdt\Entity\Season;
use Tvdt\Repository\GivenAnswerRepository;
use Tvdt\Repository\QuizRepository;
use Tvdt\Repository\SeasonRepository;
#[CoversClass(QuizRepository::class)]
final class QuizRepositoryTest extends KernelTestCase
{
private EntityManagerInterface $entityManager;
private SeasonRepository $seasonRepository;
private QuizRepository $quizRepository;
protected function setUp(): void
{
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->seasonRepository = self::getContainer()->get(SeasonRepository::class);
$this->quizRepository = self::getContainer()->get(QuizRepository::class);
parent::setUp();
}
public function testClearQuiz(): void
{
$krtekSeason = $this->seasonRepository->findOneBy(['seasonCode' => 'krtek']);
$this->assertInstanceOf(Season::class, $krtekSeason);
$quiz = $krtekSeason->activeQuiz;
$this->assertInstanceOf(Quiz::class, $quiz);
$this->quizRepository->clearQuiz($quiz);
$this->entityManager->refresh($krtekSeason);
$this->assertEmpty($quiz->candidateData);
$this->assertEmpty($quiz->eliminations);
/** @var GivenAnswerRepository $givenAnswerRepository */
$givenAnswerRepository = self::getContainer()->get(GivenAnswerRepository::class);
$this->assertEmpty($givenAnswerRepository->findBy(['quiz' => $quiz]));
}
public function testDeleteQuiz(): void
{
$krtekSeason = $this->seasonRepository->findOneBy(['seasonCode' => 'krtek']);
$this->assertInstanceOf(Season::class, $krtekSeason);
$quiz = $krtekSeason->quizzes->last();
$this->assertInstanceOf(Quiz::class, $quiz);
$this->quizRepository->deleteQuiz($quiz);
$this->entityManager->refresh($krtekSeason);
$this->assertCount(1, $krtekSeason->quizzes);
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tvdt\Tests\Security\Voter; namespace Tvdt\Tests\Security\Voter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -18,6 +19,7 @@ use Tvdt\Entity\Season;
use Tvdt\Entity\User; use Tvdt\Entity\User;
use Tvdt\Security\Voter\SeasonVoter; use Tvdt\Security\Voter\SeasonVoter;
#[CoversClass(SeasonVoter::class)]
final class SeasonVoterTest extends TestCase final class SeasonVoterTest extends TestCase
{ {
private SeasonVoter $seasonVoter; private SeasonVoter $seasonVoter;