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

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

View File

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

View File

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

View File

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