Ajout de tests
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
4498de7839
commit
6359969856
@ -0,0 +1 @@
|
|||||||
|
{"version":1,"defects":{"MaClasseTest::testMethode":5,"toto::testMethode":5,"AuthServiceTest::testLoginWithValidCredentials":5,"AuthServiceTest::testLoginWithInvalidUsername":5,"AuthServiceTest::testLoginWithInvalidPassword":5,"AuthServiceTest::testRegisterNewUser":5,"AuthServiceTest::testRegisterWithExistingUser":4,"AuthServiceTest::testLogoutUserMethodNotImplemented":5},"times":{"MaClasseTest::testMethode":0.03,"toto::testMethode":0.037,"AuthServiceTest::testLoginWithValidCredentials":0.088,"AuthServiceTest::testLoginWithInvalidUsername":0.005,"AuthServiceTest::testLoginWithInvalidPassword":0.004,"AuthServiceTest::testRegisterNewUser":0.084,"AuthServiceTest::testRegisterWithExistingUser":0,"AuthServiceTest::testLogoutUserMethodNotImplemented":0.005}}
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class MaClasseTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testMethode()
|
|
||||||
{
|
|
||||||
echo "TEST MEC";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Stub\AuthService;
|
||||||
|
use Model\Coach;
|
||||||
|
use Model\Athlete;
|
||||||
|
|
||||||
|
use Model\User;
|
||||||
|
use Shared\Exception\NotImplementedException;
|
||||||
|
use Network\IAuthService;
|
||||||
|
use Shared\HashPassword;
|
||||||
|
use Stub\UserRepository;
|
||||||
|
|
||||||
|
class AuthServiceTest extends TestCase{
|
||||||
|
public function testLoginWithValidCredentials() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Create a user for testing
|
||||||
|
$user = new User(6, "Truc", "Test", "truc.test@example.com", "test123", "M", 1.75, 80, new \DateTime("2000-01-01"), new Athlete);
|
||||||
|
$userRepository->addItem($user);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$result = $authService->login($user->getNom(), "test123");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertInstanceOf(User::class, $result);
|
||||||
|
// Add more assertions if needed
|
||||||
|
}
|
||||||
|
public function testLoginWithInvalidUsername() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Act and Assert
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
$authService->login("Machin", "password123");
|
||||||
|
}
|
||||||
|
public function testLoginWithInvalidPassword() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Create a user for testing
|
||||||
|
$user = new User(6, "Truc", "Test", "truc.test@example.com", "test123", "M", 1.75, 80, new \DateTime("2000-01-01"), new Athlete);
|
||||||
|
$userRepository->addItem($user);
|
||||||
|
|
||||||
|
// Act and Assert
|
||||||
|
$this->assertNull($authService->login($user->getNom(), "machin"));
|
||||||
|
}
|
||||||
|
public function testRegisterNewUser() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$result = $authService->register("truc.test@example.com", "test123", array("prenom"=>"Truc", "nom"=>"Test", "email"=>"truc.test@example.com", "sexe"=>"M","poids"=>1.75, "taille"=>80,"dateNaissance"=>new \DateTime("2000-01-01"), "roleName"=>"Athlete"));
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertTrue($result);
|
||||||
|
// Add more assertions if needed
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public function testRegisterWithExistingUser() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Create an existing user for testing
|
||||||
|
$existingUser = new User(6, "Truc", "Test", "truc.test@example.com", "test123", "M", 1.75, 80, new \DateTime("2000-01-01"), new Athlete);
|
||||||
|
$userRepository->addItem($existingUser);
|
||||||
|
|
||||||
|
// Act and Assert
|
||||||
|
$this->expectException(\Exception::class);
|
||||||
|
$authService->register($existingUser->getNom(), "test123", array("prenom"=>"Truc", "nom"=>"Test", "email"=>"truc.test@example.com", "sexe"=>"M","poids"=>1.75, "taille"=>80,"dateNaissance"=>new \DateTime("2000-01-01"), "roleName"=>"Athlete"));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public function testLogoutUserMethodNotImplemented() {
|
||||||
|
// Arrange
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$passwordHasher = new HashPassword();
|
||||||
|
$authService = new AuthService($userRepository, $passwordHasher);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$this->expectOutputString('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! logout method not implemented !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
||||||
|
$authService->logoutUser();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue