diff --git a/app/src/Domain/Repository/User/UserRepository.php b/app/src/Domain/Repository/User/UserRepository.php index 3d7690f..2e90a03 100644 --- a/app/src/Domain/Repository/User/UserRepository.php +++ b/app/src/Domain/Repository/User/UserRepository.php @@ -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()), diff --git a/app/tests/Domain/Repository/UserRepositoryTest.php b/app/tests/Domain/Repository/UserRepositoryTest.php index b44d6d8..6a69703 100644 --- a/app/tests/Domain/Repository/UserRepositoryTest.php +++ b/app/tests/Domain/Repository/UserRepositoryTest.php @@ -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") + ); } }