Updated the episode repository, look for any other instances of the insert method from the database handler.

This commit is contained in:
Dave Smith-Hayes 2024-11-18 02:54:45 +00:00
parent 8ab60512aa
commit 0825c098e5
5 changed files with 16 additions and 14 deletions

View File

@ -14,6 +14,12 @@ class UserRepository implements UserRepositoryInterface
const CREATE_QUERY = "INSERT INTO users (email, password, name) const CREATE_QUERY = "INSERT INTO users (email, password, name)
VALUES (:email, :password, :name)"; VALUES (:email, :password, :name)";
const UPDATE_QUERY = "UPDATE users
SET email = :email,
name = :name,
password = :password
WHERE id = :id";
public function __construct( public function __construct(
private DatabaseHandlerInterface $db, private DatabaseHandlerInterface $db,
private UserAuthorizationInterface $userAuth private UserAuthorizationInterface $userAuth
@ -70,7 +76,7 @@ class UserRepository implements UserRepositoryInterface
public function create(User $user): bool public function create(User $user): bool
{ {
$results = $this->db->insert(self::CREATE_QUERY, [ $results = $this->db->execute(self::CREATE_QUERY, [
':email' => $user->getEmail(), ':email' => $user->getEmail(),
':password' => $this->userAuth->hash($user->getPassword()), ':password' => $this->userAuth->hash($user->getPassword()),
':name' => $user->getName(), ':name' => $user->getName(),
@ -94,11 +100,11 @@ class UserRepository implements UserRepositoryInterface
password = :password password = :password
WHERE id = :id"; WHERE id = :id";
$results = (bool) $this->db->query($query, [ $results = $this->db->execute(self::UPDATE_QUERY, [
$user->getEmail(), ':email' => $user->getEmail(),
$user->getName(), ':name' => $user->getName(),
$this->userAuth->hash($user->getPassword()), ':password' => $this->userAuth->hash($user->getPassword()),
$user->getId() ':id' => $user->getId()
]); ]);
if ($results == true) { if ($results == true) {

View File

@ -29,5 +29,5 @@ interface DatabaseHandlerInterface
* @param array $params Either a list of params, or the KV of params * @param array $params Either a list of params, or the KV of params
* @return bool True if successful * @return bool True if successful
*/ */
public function insert(string $query, array $params = []): bool; public function execute(string $query, array $params = []): bool;
} }

View File

@ -49,7 +49,7 @@ class DatabaseHandler implements DatabaseHandlerInterface
return $statement->fetchAll($params); return $statement->fetchAll($params);
} }
public function insert(string $query, array $params = []): bool public function execute(string $query, array $params = []): bool
{ {
$statement = $this->database->prepare($query); $statement = $this->database->prepare($query);
return $statement->execute($params); return $statement->execute($params);

View File

@ -17,8 +17,8 @@ class UserRepositoryTest extends TestCase
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class); $databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
$databaseHandler $databaseHandler
->insert(Argument::type('string'), Argument::type('array')) ->execute(Argument::type('string'), Argument::type('array'))
->willReturn(true); ->willReturn(true, true);
$databaseHandler $databaseHandler
->getConnection() ->getConnection()
@ -29,10 +29,6 @@ class UserRepositoryTest extends TestCase
} }
}); });
$databaseHandler
->query(Argument::type('string'), Argument::type('array'))
->willReturn([true]);
$userRepository = new UserRepository( $userRepository = new UserRepository(
$databaseHandler->reveal(), $databaseHandler->reveal(),
new BasicUserAuthorization() new BasicUserAuthorization()