Files
crm_ecosplay/tests/Service/UserManagementServiceTest.php
Serreau Jovann 6fa970e60d refactor: rebrand project to CRM SITECONSEIL (SARL SITECONSEIL)
- Rename all references from E-Cosplay/Ecosplay to SITECONSEIL
- Update entity from Association to SARL SITECONSEIL (Siret: 418664058)
- Update address to 27 rue Le Serurier, 02100 Saint-Quentin
- Update emails: contact@siteconseil.fr, rgpd@siteconseil.fr
- Update hosting from GCP to OVHcloud (Roubaix, Gravelines, Strasbourg, Paris)
- Update legal pages: mentions legales, CGV, RGPD, conformite, hebergement, cookies, CGU
- Add tarifs page with tabs: Site Internet, E-Commerce, Nom de domaine, Esy-Mail, Esy-Mailer, Esy-Tchat, Esy-Meet, Esy-Defender
- Add Discord webhook notification workflow
- Disable deploy and sonarqube workflows
- Update OAuth Keycloak realm to master
- Update logo references to logo_facture.png
- Remove forced image sizing in Liip Imagine filters
- Update SonarQube project key and badge token
- Update tribunal competent to Saint-Quentin
- Move tarif tabs JS to app.js (CSP compliance)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 18:48:25 +02:00

82 lines
2.9 KiB
PHP

<?php
namespace App\Tests\Service;
use App\Entity\User;
use App\Exception\UserAlreadyExistsException;
use App\Repository\UserRepository;
use App\Service\UserManagementService;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
class UserManagementServiceTest extends TestCase
{
private UserRepository $userRepository;
private EntityManagerInterface $em;
private UserPasswordHasherInterface $passwordHasher;
private UserManagementService $service;
protected function setUp(): void
{
$this->userRepository = $this->createStub(UserRepository::class);
$this->em = $this->createStub(EntityManagerInterface::class);
$this->passwordHasher = $this->createStub(UserPasswordHasherInterface::class);
$this->service = new UserManagementService(
$this->userRepository,
$this->em,
$this->passwordHasher
);
}
public function testCreateBaseUserSuccess(): void
{
$email = 'test@example.com';
$firstName = 'John';
$lastName = 'Doe';
$roles = ['ROLE_USER'];
$userRepository = $this->createStub(UserRepository::class);
$userRepository->method('findOneBy')->willReturn(null);
$passwordHasher = $this->createStub(UserPasswordHasherInterface::class);
$passwordHasher->method('hashPassword')->willReturn('hashed_password');
$em = $this->createMock(EntityManagerInterface::class);
$em->expects($this->once())
->method('persist')
->with($this->isInstanceOf(User::class));
$service = new UserManagementService($userRepository, $em, $passwordHasher);
$user = $service->createBaseUser($email, $firstName, $lastName, $roles);
$this->assertEquals($email, $user->getEmail());
$this->assertEquals($firstName, $user->getFirstName());
$this->assertEquals($lastName, $user->getLastName());
$this->assertEquals($roles, $user->getRoles());
$this->assertEquals('hashed_password', $user->getPassword());
$this->assertNotEmpty($user->getTempPassword());
}
public function testCreateBaseUserThrowsExceptionIfUserExists(): void
{
$email = 'existing@example.com';
$userRepository = $this->createStub(UserRepository::class);
$userRepository->method('findOneBy')->willReturn(new User());
$service = new UserManagementService($userRepository, $this->em, $this->passwordHasher);
$this->expectException(UserAlreadyExistsException::class);
$service->createBaseUser($email, 'John', 'Doe', []);
}
public function testCreateBaseUserThrowsExceptionIfInvalidData(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->service->createBaseUser('', 'John', 'Doe', []);
}
}