diff --git a/Sources/tests/units/repository/UserRepositoryTest.php b/Sources/tests/units/repository/UserRepositoryTest.php new file mode 100644 index 00000000..40de6b7b --- /dev/null +++ b/Sources/tests/units/repository/UserRepositoryTest.php @@ -0,0 +1,92 @@ +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)); + } +}