Commit 690a7201 authored by BuildTools's avatar BuildTools
Browse files

make ParticipantMakeEventCourseTest and fix extract from track for point event score

parent 5cc706ab
......@@ -348,7 +348,7 @@ class EventController extends AbstractController
$success = "success";
}
}
dump($event->getCSV($this->getDoctrine()->getRepository(ParticipantMakeEventCourse::class)));
return $this->render('event/event_info.html.twig',
[
'event' => $event,
......
......@@ -24,7 +24,7 @@ class EventCourseFixtures extends Fixture implements DependentFixtureInterface
$eventCourse->setFormat(0);
$eventCourse->setMissingPunchPenalty(12);
$eventCourse->setOverTimePenalty(12);
$eventCourse->setMaxTime(0);
$eventCourse->setMaxTime(2400000);
$manager->persist($eventCourse);
$this->addReference(self::LUC_CHAMPIONSHIP_EVENTCOURSE_REFERENCE, $eventCourse);
......
......@@ -151,7 +151,7 @@ class ParticipantMakeEventCourse
if ($this->track !== null) {
if ($this->eventCourse->getMaxTime() !== 0) {
$overTime = $this->track->getTotalTime() - $this->eventCourse->getMaxTime();
if ($this->eventCourse->getMaxTime() != 0 && $overTime > 0) {
if ($this->eventCourse->getMaxTime() !== 0 && $overTime > 0) {
if ($overTime / 1000 >= 60) {
$this->nbOverTimePenalty = floor(($overTime / 1000) / 60);
$overTime = ($overTime / 1000) % $this->nbOverTimePenalty;
......@@ -174,9 +174,10 @@ class ParticipantMakeEventCourse
foreach ($t->RaceCourseData->Course->CourseControl as $y) {
if ((string)$y->attributes()["type"] === "Control") {
if ((int)$this->track->getControlPoints()[$balise]->punchTime !== 0) {
if ($y->Score !== null) {
if (isset($y->Score)) {
$this->score += (int)$y->Score;
} else {
$this->score += 1;
}
}
......
<?php
namespace App\Tests\Entity;
use App\Entity\Event;
use App\Entity\ParticipantMakeEventCourse;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ParticipantMakeEventCourseTest extends KernelTestCase
{
/**
* @var \Doctrine\ORM\EntityManager
*/
private $entityManager;
protected function setUp(): void
{
$kernel = self::bootKernel();
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
}
public function testRemove()
{
$nbParticipantMakeEventCourse = count($this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll());
$participantMakeEventCourse = $this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll()[0];
$participantMakeEventCourse->remove($this->entityManager);
$this->assertSame($nbParticipantMakeEventCourse, count($this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll()) + 1);
}
public function testExtractFromTrackNbOverTimePenalty()
{
$championship = null;
foreach ($this->entityManager->getRepository(Event::class)->findAll() as $event) {
if ($event->getType() === 0) {
$championship = $event;
}
}
$eric = null;
foreach ($championship->getParticipants() as $participant) {
if ($participant->getNickName() === "Eric") {
$eric = $participant;
}
}
$luc = null;
foreach ($championship->getEventCourses() as $eventCourse) {
if ($eventCourse->getCourse()->getName() === "Luc") {
$luc = $eventCourse;
}
}
$participantMakeEventCourse = $this->entityManager->getRepository(ParticipantMakeEventCourse::class)->find(array("eventCourse" => $luc, "participant" => $eric));
$participantMakeEventCourse->extractFromTrack();
$this->assertSame(3, $participantMakeEventCourse->getNbOverTimePenalty());
}
public function testExtractFromTrackNbMissingPunchPenalty()
{
$championship = null;
foreach ($this->entityManager->getRepository(Event::class)->findAll() as $event) {
if ($event->getType() === 0) {
$championship = $event;
}
}
$eric = null;
foreach ($championship->getParticipants() as $participant) {
if ($participant->getNickName() === "Eric") {
$eric = $participant;
}
}
$luc = null;
foreach ($championship->getEventCourses() as $eventCourse) {
if ($eventCourse->getCourse()->getName() === "Luc") {
$luc = $eventCourse;
}
}
$participantMakeEventCourse = $this->entityManager->getRepository(ParticipantMakeEventCourse::class)->find(array("eventCourse" => $luc, "participant" => $eric));
$participantMakeEventCourse->extractFromTrack();
$this->assertSame(1, $participantMakeEventCourse->getNbMissingPunchPenalty());
}
public function testExtractFromTrackScore()
{
$championship = null;
foreach ($this->entityManager->getRepository(Event::class)->findAll() as $event) {
if ($event->getType() === 1) {
$championship = $event;
}
}
$eric = null;
foreach ($championship->getParticipants() as $participant) {
if ($participant->getNickName() === "Eric") {
$eric = $participant;
}
}
$luc = null;
foreach ($championship->getEventCourses() as $eventCourse) {
if ($eventCourse->getCourse()->getName() === "Luc") {
$luc = $eventCourse;
}
}
$participantMakeEventCourse = $this->entityManager->getRepository(ParticipantMakeEventCourse::class)->find(array("eventCourse" => $luc, "participant" => $eric));
$participantMakeEventCourse->extractFromTrack();
$this->assertSame(6, $participantMakeEventCourse->getScore());
}
protected function tearDown(): void
{
parent::tearDown();
$this->entityManager->close();
$this->entityManager = null;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment