Updated the episode repository, look for any other instances of the insert method from the database handler.
This commit is contained in:
parent
8ab60512aa
commit
0825c098e5
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user