Tests UserManager non fonctionnels
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
afc107ef93
commit
98e7c22cb9
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Manager\UserManager;
|
||||
use Model\User;
|
||||
use Model\Coach;
|
||||
use Model\Athlete;
|
||||
use Network\IAuthService;
|
||||
|
||||
class UserManagerTest extends TestCase
|
||||
{
|
||||
private $authService;
|
||||
private $userManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->authService = $this->createMock(IAuthService::class);
|
||||
$this->userManager = new UserManager($this->authService);
|
||||
}
|
||||
|
||||
public function testLoginSuccess()
|
||||
{
|
||||
$loginUser = 'john.doe@example.com';
|
||||
$passwordUser = 'password123';
|
||||
$mockUser = new User(1, "Doe", "John", $loginUser, $passwordUser, 'M', 1.80, 75, new \DateTime("1985-05-15"), new Coach());
|
||||
|
||||
$this->authService->expects($this->once())
|
||||
->method('login')
|
||||
->with($loginUser, $passwordUser)
|
||||
->willReturn($mockUser);
|
||||
|
||||
$result = $this->userManager->login($loginUser, $passwordUser);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertSame($mockUser, $this->userManager->currentUser);
|
||||
}
|
||||
|
||||
public function testLoginFailure()
|
||||
{
|
||||
$loginUser = 'john.doe@example.com';
|
||||
$passwordUser = 'wrong_password';
|
||||
|
||||
// Configure authService to return null during login
|
||||
$this->authService->expects($this->once())
|
||||
->method('login')
|
||||
->with($loginUser, $passwordUser)
|
||||
->willReturn(null);
|
||||
|
||||
// Ensure currentUser is null before attempting to access it
|
||||
$this->assertNull($this->userManager->currentUser);
|
||||
|
||||
$result = $this->userManager->login($loginUser, $passwordUser);
|
||||
|
||||
$this->assertFalse($result);
|
||||
$this->assertNull($this->userManager->currentUser);
|
||||
}
|
||||
|
||||
public function testRegisterSuccess()
|
||||
{
|
||||
$loginUser = 'new.user@example.com';
|
||||
$passwordUser = 'newpassword123';
|
||||
$data = [
|
||||
'nom' => 'New',
|
||||
'prenom' => 'User',
|
||||
'taille' => 1.75,
|
||||
'poids' => 70,
|
||||
'roleName' => 'Athlete',
|
||||
'sexe' => 'M',
|
||||
];
|
||||
|
||||
$this->authService->expects($this->once())
|
||||
->method('register')
|
||||
->with($loginUser, $passwordUser, $data)
|
||||
->willReturn(true);
|
||||
|
||||
$result = $this->userManager->register($loginUser, $passwordUser, $data);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
/* Manque les Exception
|
||||
public function testRegisterValidationException(){
|
||||
$loginUser = 'invalid.user@example.com';
|
||||
$passwordUser = 'invalidpassword123';
|
||||
$data = [
|
||||
'nom' => 'Invalid',
|
||||
'prenom' => 'User',
|
||||
'taille' => 1.75,
|
||||
'poids' => 70,
|
||||
'roleName' => 'Athlete',
|
||||
'sexe' => 'M',
|
||||
];
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->userManager->register($loginUser, $passwordUser, $data);
|
||||
}
|
||||
*/
|
||||
/* Manque la fonction de déconnexion
|
||||
public function testDeconnecterSuccess(){
|
||||
$this->authService->expects($this->once())
|
||||
->method('logoutUser');
|
||||
|
||||
$result = $this->userManager->deconnecter();
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
||||
public function testDeconnecterFailure(){
|
||||
$this->authService->expects($this->once())
|
||||
->method('logoutUser');
|
||||
|
||||
$result = $this->userManager->deconnecter();
|
||||
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in new issue