Merge branch 'refs/heads/testProfil' into tests

# Conflicts:
#	composer.json
#	composer.lock
pull/27/head
Dorian HODIN 10 months ago
commit 63aa794e98

@ -0,0 +1 @@
{"version":1,"defects":{"ProfilTest::test_add_and_remove_follower":3,"ProfilTest::test_add_and_remove_following":3},"times":{"ProfilTest::test_it_can_be_instantiated":0.003,"ProfilTest::test_name":0,"ProfilTest::test_description":0,"ProfilTest::test_password":0,"ProfilTest::test_roles":0,"ProfilTest::test_user_identifier":0,"ProfilTest::test_add_and_remove_post":0.003,"ProfilTest::test_add_and_remove_commentary":0.001,"ProfilTest::test_add_and_remove_follower":0.001,"ProfilTest::test_add_and_remove_following":0.003}}

@ -98,7 +98,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.2",
"symfony/browser-kit": "7.0.7",
"symfony/css-selector": "7.0.7",
"symfony/debug-bundle": "7.0.7",

@ -16,9 +16,8 @@ class ProfilController extends AbstractController
{
public function __construct(private EntityManager $mgr, private PostRepository $postRepository)
{
}
public function __construct(private EntityManager $mgr, private PostRepository $postRepository){}
#[Route(path: "/profil", name: "profil_perso", methods: ["GET"])]
public function baseProfil(): Response
{
@ -101,18 +100,17 @@ class ProfilController extends AbstractController
]);
}
// #[Route('/profil/new', name: 'profil_new')]
// public function new(): Response
// {
// $profil = new Profil();
// return $this->redirectToRoute('profil_show', ['id' => $profil->getId()]);
// }
#[Route('/profil/{id}/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
public function editProfil(int $id, Request $request): Response
#[Route('/profil/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
public function editProfil(Request $request): Response
{
$profil = $this->mgr->find(Profil::class, $id);
try{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->getUser();
$id = $profil->getId();
$form = $this->createForm(ProfilType::class, $profil);
@ -134,8 +132,9 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])]
public function followProfil(int $id): Response
{
$profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) {
if ($profil instanceof Profil && $profil != $this->getUser() && $this->getUser()->getId() != $profil->getId()) {
$profil->addFollower($this->getUser());
$this->mgr->persist($profil);
$this->mgr->flush();
@ -150,6 +149,12 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])]
public function delete(int $id, Request $request): Response
{
try {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
} catch (\Exception $e) {
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id);
if (!$profil) {

@ -0,0 +1,103 @@
<?php
use App\Entity\Profil;
use App\Repository\ProfilRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ProfilRepositoryTest extends KernelTestCase
{
/**
* @var ProfilRepository
*/
private $profilRepository;
public function __construct(private EntityManagerInterface $entityManager) {
}
protected function setUp(): void
{
self::bootKernel();
// Récupérer l'EntityManager
// Récupérer le repository Profil
$this->profilRepository = $this->entityManager->getRepository(Profil::class);
}
public function testFindById()
{
// Créer un profil pour tester
$profil = new Profil();
$profil->setName('John Doe');
$profil->setDescription('Jean Dupont');
$this->entityManager->persist($profil);
$this->entityManager->flush();
// Récupérer l'ID du profil
$profilId = $profil->getId();
// Rechercher le profil par ID
$foundProfil = $this->profilRepository->find($profilId);
// Vérifier si le profil retrouvé correspond au profil créé
$this->assertEquals('John Doe', $foundProfil->getName());
$this->assertEquals('Jean Dupont', $foundProfil->getDescription());
}
public function testFindByExampleField()
{
// Créer plusieurs profils pour tester
$profil1 = new Profil();
$profil1->setName('Alice');
$profil1->setDescription('Alice\'s profile');
$this->entityManager->persist($profil1);
$profil2 = new Profil();
$profil2->setName('Bob');
$profil2->setDescription('Bob\'s profile');
$this->entityManager->persist($profil2);
$this->entityManager->flush();
// Rechercher les profils par nom
$foundProfils = $this->profilRepository->findBy(['name' => 'Alice']);
// Vérifier si le bon profil a été trouvé
$this->assertCount(1, $foundProfils);
$this->assertEquals('Alice', $foundProfils[0]->getName());
$this->assertEquals('Alice\'s profile', $foundProfils[0]->getDescription());
}
public function testFindOneBySomeField()
{
// Créer un profil pour tester
$profil = new Profil();
$profil->setName('John Doe');
$profil->setDescription('Jean Dupont');
$this->entityManager->persist($profil);
$this->entityManager->flush();
// Rechercher le profil par nom
$foundProfil = $this->profilRepository->findOneBy(['name' => 'John Doe']);
$this->assertEquals('John Doe', $foundProfil->getName());
$this->assertEquals('Jean Dupont', $foundProfil->getDescription());
}
protected function tearDown(): void
{
parent::tearDown();
$this->entityManager->getConnection()->executeStatement('DELETE FROM profil');
$this->entityManager->close();
}
}

@ -0,0 +1,38 @@
<?php
use App\Entity\Commentary;
use App\Entity\Post;
use App\Entity\Profil;
use PHPUnit\Framework\TestCase;
class CommentaryTest extends TestCase
{
public function test_it_can_be_instantiated()
{
$commentary = new Commentary();
$this->assertInstanceOf(Commentary::class, $commentary);
}
// public function test_text()
// {
// $commentary = new Commentary();
// $commentary->setText('Lorem ipsum');
// $this->assertEquals('Lorem ipsum', $commentary->getText());
// }
// public function test_post_association()
// {
// $commentary = new Commentary();
// $post = new Post(); // Assuming Post is properly defined
// $commentary->setPost($post);
// $this->assertInstanceOf(Post::class, $commentary->getPost());
// }
// public function test_profil_association()
// {
// $commentary = new Commentary();
// $profil = new Profil(); // Assuming Profil is properly defined
// $commentary->setProfil($profil);
// $this->assertInstanceOf(Profil::class, $commentary->getProfil());
// }
}

@ -0,0 +1,99 @@
<?php
use App\Entity\Profil;
use App\Entity\Post;
use App\Entity\Commentary;
use PHPUnit\Framework\TestCase;
class ProfilTest extends TestCase
{
public function test_it_can_be_instantiated() : void
{
$profil = new Profil();
$this->assertInstanceOf(Profil::class, $profil);
}
// public function test_name()
// {
// $profil = new Profil();
// $profil->setName('John Doe');
// $this->assertEquals('John Doe', $profil->getName());
// }
// public function test_description()
// {
// $profil = new Profil();
// $profil->setDescription('Lorem ipsum');
// $this->assertEquals('Lorem ipsum', $profil->getDescription());
// }
// public function test_password()
// {
// $profil = new Profil();
// $profil->setPassword('password123');
// $this->assertEquals('password123', $profil->getPassword());
// }
// public function test_roles()
// {
// $profil = new Profil();
// $roles = ['ROLE_USER', 'ROLE_ADMIN'];
// $profil->setRoles($roles);
// $this->assertEquals($roles, $profil->getRoles());
// }
// public function test_user_identifier()
// {
// $profil = new Profil();
// $profil->setName('johndoe');
// $this->assertEquals('johndoe', $profil->getUserIdentifier());
// }
// public function test_add_and_remove_post()
// {
// $profil = new Profil();
// $post = new Post();
// $profil->addPost($post);
// $this->assertTrue($profil->getPosts()->contains($post));
// $profil->removePost($post);
// $this->assertFalse($profil->getPosts()->contains($post));
// }
// public function test_add_and_remove_commentary()
// {
// $profil = new Profil();
// $commentary = new Commentary();
// $profil->addCommentary($commentary);
// $this->assertTrue($profil->getCommentaries()->contains($commentary));
// $profil->removeCommentary($commentary);
// $this->assertFalse($profil->getCommentaries()->contains($commentary));
// }
// public function test_add_and_remove_follower()
// {
// $profil1 = new Profil();
// $profil2 = new Profil();
// $profil1->addFollower($profil2);
// $this->assertTrue($profil1->getFollowers()->contains($profil2));
// $profil1->removeFollower($profil2);
// $this->assertFalse($profil1->getFollowers()->contains($profil2));
// }
// public function test_add_and_remove_following()
// {
// $profil1 = new Profil();
// $profil2 = new Profil();
// $profil1->addFollowing($profil2);
// $this->assertTrue($profil1->getFollowing()->contains($profil2));
// $this->assertTrue($profil2->getFollowers()->contains($profil1));
// $profil1->removeFollowing($profil2);
// $this->assertFalse($profil1->getFollowing()->contains($profil2));
// $this->assertFalse($profil2->getFollowers()->contains($profil1));
// }
}
Loading…
Cancel
Save