Improve testing of middleware.

This commit is contained in:
James Cole
2017-12-26 17:33:53 +01:00
parent f7652e7f01
commit 9e3f31f2f0
15 changed files with 765 additions and 12 deletions

View File

@@ -168,6 +168,16 @@ class UserRepository implements UserRepositoryInterface
return User::where('email', $email)->first();
}
/**
* Returns the first user in the DB. Generally only works when there is just one.
*
* @return null|User
*/
public function first(): ?User
{
return User::first();
}
/**
* Return basic user information.
*
@@ -225,6 +235,23 @@ class UserRepository implements UserRepositoryInterface
return $user->hasRole($role);
}
/**
* @param array $data
*
* @return User
*/
public function store(array $data): User
{
$password = bcrypt($data['password'] ?? app('str')->random(16));
return User::create(
[
'email' => $data['email'],
'password' => $password,
]
);
}
/**
* @param User $user
*/

View File

@@ -37,6 +37,20 @@ interface UserRepositoryInterface
*/
public function all(): Collection;
/**
* Returns the first user in the DB. Generally only works when there is just one.
*
* @return null|User
*/
public function first(): ?User;
/**
* @param array $data
*
* @return User
*/
public function store(array $data): User;
/**
* Gives a user a role.
*