You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.8 KiB
93 lines
2.8 KiB
<?php
|
|
use PHPUnit\Framework\TestCase;
|
|
use Stub\UserRepository;
|
|
use Model\User;
|
|
use Model\Coach;
|
|
use Model\Athlete;
|
|
|
|
class UserRepositoryTest extends TestCase
|
|
{
|
|
private $userRepository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->userRepository = new UserRepository();
|
|
}
|
|
|
|
public function testGetItemById()
|
|
{
|
|
$user = $this->userRepository->getItemById(1);
|
|
$this->assertInstanceOf(User::class, $user);
|
|
$this->assertSame("Doe", $user->getNom());
|
|
}
|
|
|
|
public function testGetItemByEmail()
|
|
{
|
|
$user = $this->userRepository->getItemByEmail("jane.smith@example.com");
|
|
$this->assertInstanceOf(User::class, $user);
|
|
$this->assertSame("Smith", $user->getNom());
|
|
}
|
|
|
|
public function testGetNbItems()
|
|
{
|
|
$count = $this->userRepository->GetNbItems();
|
|
$this->assertSame(5, $count);
|
|
}
|
|
|
|
public function testGetItems()
|
|
{
|
|
$items = $this->userRepository->GetItems(0, 2);
|
|
$this->assertCount(2, $items);
|
|
$this->assertInstanceOf(User::class, $items[0]);
|
|
$this->assertInstanceOf(User::class, $items[1]);
|
|
}
|
|
|
|
public function testGetItemsByName()
|
|
{
|
|
$items = $this->userRepository->GetItemsByName("John", 0, 2);
|
|
$this->assertCount(1, $items);
|
|
$this->assertInstanceOf(User::class, $items[0]);
|
|
$this->assertSame("John", $items[0]->getPrenom());
|
|
}
|
|
|
|
public function testGetItemByName()
|
|
{
|
|
$item = $this->userRepository->GetItemByName("Doe", 0, 2);
|
|
$this->assertInstanceOf(User::class, $item);
|
|
$this->assertSame("Doe", $item->getNom());
|
|
}
|
|
|
|
public function testUpdateItem()
|
|
{
|
|
$oldUser = $this->userRepository->getItemById(1);
|
|
$newUser = new User(1, "UpdatedDoe", "John", "john.doe@example.com", "newpassword", 'M', 1.80, 75, new \DateTime("1985-05-15"), new Coach());
|
|
|
|
$this->userRepository->UpdateItem($oldUser, $newUser);
|
|
|
|
$updatedUser = $this->userRepository->getItemById(1);
|
|
$this->assertSame("UpdatedDoe", $updatedUser->getNom());
|
|
$this->assertSame("newpassword", $updatedUser->getMotDePasse());
|
|
}
|
|
|
|
public function testAddItem()
|
|
{
|
|
$newUser = new User(6, "NewUser", "Test", "new.user@example.com", "newpassword123", 'F', 1.70, 60, new \DateTime("1990-01-01"), new Athlete());
|
|
|
|
$this->userRepository->AddItem($newUser);
|
|
|
|
$addedUser = $this->userRepository->getItemById(6);
|
|
$this->assertInstanceOf(User::class, $addedUser);
|
|
$this->assertSame("NewUser", $addedUser->getNom());
|
|
}
|
|
|
|
public function testDeleteItem()
|
|
{
|
|
$userToDelete = $this->userRepository->getItemById(1);
|
|
|
|
$result = $this->userRepository->DeleteItem($userToDelete);
|
|
|
|
$this->assertTrue($result);
|
|
$this->assertNull($this->userRepository->getItemById(1));
|
|
}
|
|
}
|