Commit 2a3715db authored by BuildTools's avatar BuildTools
Browse files

redo the course with the same nickname don't overide previus course + ParticipantTest

parent 690a7201
......@@ -29,13 +29,13 @@ class DataController extends AbstractController
$courses = $this->getDoctrine()->getRepository(Course::class)->findAll();
$dataCourses = [];
foreach ($courses as $course) {
$info = array(
"id" => $course->getId(),
"name" => $course->getName(),
"latitude" => $course->getLatitude(),
"longitude" => $course->getLongitude(),
"length" => $course->getLength(),
);
$info = array(
"id" => $course->getId(),
"name" => $course->getName(),
"latitude" => $course->getLatitude(),
"longitude" => $course->getLongitude(),
"length" => $course->getLength(),
);
if ($course->getClub() !== null) {
$info["club"] = $course->getClub();
}
......@@ -113,7 +113,7 @@ class DataController extends AbstractController
try {
$this->checkAndAddToEvent($trackCreator->getTrack());
} catch (Exception $e) {
$error=$e;
$error = $e;
}
return new JsonResponse(
[
......@@ -171,11 +171,13 @@ class DataController extends AbstractController
foreach ($event->getParticipants() as $participant) {
if ($track->getName() === $participant->getNickname()) {
$participantMakeEventCourse = $this->getDoctrine()->getRepository(ParticipantMakeEventCourse::class)->find(array("eventCourse" => $eventCourse, "participant" => $participant));
$participantMakeEventCourse->setTrack($track);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($participantMakeEventCourse);
$entityManager->flush();
$event->update($entityManager, $this->getDoctrine()->getRepository(ParticipantMakeEventCourse::class));
if ($participantMakeEventCourse->getTrack() === null) {
$participantMakeEventCourse->setTrack($track);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($participantMakeEventCourse);
$entityManager->flush();
$event->update($entityManager, $this->getDoctrine()->getRepository(ParticipantMakeEventCourse::class));
}
}
}
}
......
<?php
namespace App\Tests\Entity;
use App\Entity\Event;
use App\Entity\Participant;
use App\Entity\ParticipantMakeEventCourse;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ParticipantTest 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());
$nbParticipant = count($this->entityManager->getRepository(Participant::class)->findAll());
$participant = $this->entityManager->getRepository(Participant::class)->findAll()[0];
$participant->remove($this->entityManager, $this->entityManager->getRepository(ParticipantMakeEventCourse::class));
$this->assertSame($nbParticipantMakeEventCourse, count($this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll()) + 2);
$this->assertSame($nbParticipant, count($this->entityManager->getRepository(Participant::class)->findAll()) + 1);
}
public function testCheckNicknameFree()
{
$participant = new Participant();
$participant->setNickname("Regis");
$this->assertTrue($participant->checkNickname($this->entityManager->getRepository(Event::class)->findAll()[0]));
}
public function testCheckNicknameNotFree()
{
$participant = new Participant();
$participant->setNickname("Suliac");
$this->assertFalse($participant->checkNickname($this->entityManager->getRepository(Event::class)->findAll()[0]));
}
public function testCreate()
{
$nbParticipantMakeEventCourse = count($this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll());
$nbParticipant = count($this->entityManager->getRepository(Participant::class)->findAll());
$participant = new Participant();
$participant->setNickname("Regis");
$participant->create($this->entityManager->getRepository(Event::class)->findAll()[0], $this->entityManager);
$this->assertSame($nbParticipantMakeEventCourse + 2, count($this->entityManager->getRepository(ParticipantMakeEventCourse::class)->findAll()));
$this->assertSame($nbParticipant + 1, count($this->entityManager->getRepository(Participant::class)->findAll()));
}
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