Add the Update change, and see what changes need to happen to the DB handler's methods

This commit is contained in:
Dave Smith-Hayes 2024-11-18 02:40:16 +00:00
parent 38e61f5eb2
commit 8ab60512aa
2 changed files with 27 additions and 13 deletions

View File

@ -94,7 +94,7 @@ class UserRepository implements UserRepositoryInterface
password = :password
WHERE id = :id";
$results = $this->db->query($query, [
$results = (bool) $this->db->query($query, [
$user->getEmail(),
$user->getName(),
$this->userAuth->hash($user->getPassword()),

View File

@ -16,28 +16,42 @@ class UserRepositoryTest extends TestCase
$user = $this->getUserFromArray();
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
$databaseHandler->insert(
Argument::type('string'),
Argument::type('array')
)->willReturn(true);
$databaseHandler->getConnection()->willReturn(new class {
public function lastInsertId(): int
{
return 100;
}
});
$databaseHandler
->insert(Argument::type('string'), Argument::type('array'))
->willReturn(true);
$databaseHandler
->getConnection()
->willReturn(new class {
public function lastInsertId(): int
{
return 100;
}
});
$databaseHandler
->query(Argument::type('string'), Argument::type('array'))
->willReturn([true]);
$userRepository = new UserRepository(
$databaseHandler->reveal(),
new BasicUserAuthorization()
);
$results = $userRepository->create($user);
$this->assertTrue($results);
/**
* We are testing if the User entity has been mutated by the `create`
* method in the UserRepository.
*/
$results = $userRepository->create($user);
$this->assertTrue($results);
$this->assertEquals(100, $user->getId());
$user->setName("Dave Smith-Hayes");
$results = $userRepository->update($user);
$this->assertTrue($results);
$this->assertEquals(
$user->getUpdatedAt()->format("dmY"),
(new \DateTime())->format("dmY")
);
}
}