From 8ab60512aa654f1d04386032365214bc9f14ff2d Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Mon, 18 Nov 2024 02:40:16 +0000 Subject: [PATCH] Add the Update change, and see what changes need to happen to the DB handler's methods --- .../Domain/Repository/User/UserRepository.php | 2 +- .../Domain/Repository/UserRepositoryTest.php | 38 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) 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") + ); } }