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

View File

@ -29,5 +29,5 @@ interface DatabaseHandlerInterface
* @param array $params Either a list of params, or the KV of params
* @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);
}
public function insert(string $query, array $params = []): bool
public function execute(string $query, array $params = []): bool
{
$statement = $this->database->prepare($query);
return $statement->execute($params);

View File

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