mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 04:44:19 +01:00
Create Testcoverage and upgrade Symfomy and PHP
* Some tests * More tests! * Tests 3 * Move getScores from Candidate to Quiz * Add some suggestions for future refactoring * - **Add Gedmo doctrine-extensions and Stof bundle integration** - Added `stof/doctrine-extensions-bundle` and `gedmo/doctrine-extensions` dependencies. - Integrated `Timestampable` behavior for `Created` fields in entities. - Updated `bundles.php` to register StofDoctrineExtensionsBundle. - Added configuration for the Stof bundle. - Simplified `SeasonVoter` with `match` expression and added new tests. - Minor fixes and adjustments across various files. * WIP * All the tests * Base64 tests * Symfomny 7.4.0 * Update * Update recipe * PHP 8.5 * Rector changes * More 8.5 * Things
This commit is contained in:
@@ -7,10 +7,10 @@ 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 Safe\DateTimeImmutable;
|
||||
use Safe\Exceptions\DatetimeException;
|
||||
use Tvdt\Dto\Result;
|
||||
use Tvdt\Entity\Quiz;
|
||||
use Tvdt\Entity\QuizCandidate;
|
||||
use Tvdt\Exception\ErrorClearingQuizException;
|
||||
|
||||
/**
|
||||
@@ -29,28 +29,36 @@ 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();
|
||||
} catch (\Throwable $throwable) {
|
||||
->execute();
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
catch (\Throwable $throwable) {
|
||||
$this->logger->error($throwable->getMessage());
|
||||
$em->rollback();
|
||||
throw new ErrorClearingQuizException(previous: $throwable);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$em->commit();
|
||||
}
|
||||
|
||||
@@ -59,4 +67,40 @@ class QuizRepository extends ServiceEntityRepository
|
||||
$this->getEntityManager()->remove($quiz);
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DatetimeException
|
||||
*
|
||||
* @return list<Result>
|
||||
*/
|
||||
public function getScores(Quiz $quiz): array
|
||||
{
|
||||
$result = $this->getEntityManager()->createQuery(<<<DQL
|
||||
select
|
||||
c.id,
|
||||
c.name,
|
||||
sum(case when a.isRightAnswer = true then 1 else 0 end) as correct,
|
||||
qd.corrections,
|
||||
max(ga.created) as end_time,
|
||||
qd.created as start_time,
|
||||
(sum(case when a.isRightAnswer = true then 1 else 0 end) + qd.corrections) as score
|
||||
from Tvdt\Entity\Candidate c
|
||||
join c.givenAnswers ga
|
||||
join ga.answer a
|
||||
join c.quizData qd
|
||||
where qd.quiz = :quiz and ga.quiz = :quiz
|
||||
group by ga.quiz, c.id, qd.id
|
||||
order by score desc, max(ga.created) - qd.created asc
|
||||
DQL
|
||||
)->setParameter('quiz', $quiz)->getResult();
|
||||
|
||||
return array_map(static fn (array $row): Result => new Result(
|
||||
id: $row['id'],
|
||||
name: $row['name'],
|
||||
correct: (int) $row['correct'],
|
||||
corrections: $row['corrections'],
|
||||
time: $row['start_time']->diff(new DateTimeImmutable($row['end_time'])),
|
||||
score: $row['score'],
|
||||
), $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user