Add the Update change, and see what changes need to happen to the DB handler's methods
This commit is contained in:
parent
38e61f5eb2
commit
8ab60512aa
@ -94,7 +94,7 @@ class UserRepository implements UserRepositoryInterface
|
|||||||
password = :password
|
password = :password
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
$results = $this->db->query($query, [
|
$results = (bool) $this->db->query($query, [
|
||||||
$user->getEmail(),
|
$user->getEmail(),
|
||||||
$user->getName(),
|
$user->getName(),
|
||||||
$this->userAuth->hash($user->getPassword()),
|
$this->userAuth->hash($user->getPassword()),
|
||||||
|
@ -16,28 +16,42 @@ class UserRepositoryTest extends TestCase
|
|||||||
$user = $this->getUserFromArray();
|
$user = $this->getUserFromArray();
|
||||||
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
||||||
|
|
||||||
$databaseHandler->insert(
|
$databaseHandler
|
||||||
Argument::type('string'),
|
->insert(Argument::type('string'), Argument::type('array'))
|
||||||
Argument::type('array')
|
->willReturn(true);
|
||||||
)->willReturn(true);
|
|
||||||
$databaseHandler->getConnection()->willReturn(new class {
|
$databaseHandler
|
||||||
|
->getConnection()
|
||||||
|
->willReturn(new class {
|
||||||
public function lastInsertId(): int
|
public function lastInsertId(): int
|
||||||
{
|
{
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$databaseHandler
|
||||||
|
->query(Argument::type('string'), Argument::type('array'))
|
||||||
|
->willReturn([true]);
|
||||||
|
|
||||||
$userRepository = new UserRepository(
|
$userRepository = new UserRepository(
|
||||||
$databaseHandler->reveal(),
|
$databaseHandler->reveal(),
|
||||||
new BasicUserAuthorization()
|
new BasicUserAuthorization()
|
||||||
);
|
);
|
||||||
|
|
||||||
$results = $userRepository->create($user);
|
|
||||||
$this->assertTrue($results);
|
|
||||||
/**
|
/**
|
||||||
* We are testing if the User entity has been mutated by the `create`
|
* We are testing if the User entity has been mutated by the `create`
|
||||||
* method in the UserRepository.
|
* method in the UserRepository.
|
||||||
*/
|
*/
|
||||||
|
$results = $userRepository->create($user);
|
||||||
|
$this->assertTrue($results);
|
||||||
$this->assertEquals(100, $user->getId());
|
$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")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user