I have a small middle ware for which I would like to write a test for.. I would like to do two tests:
- Mock role_id with 1; handle should return TRUE
- Mock role_id with 2; handle should return FALSE
How can this be done?
namespace App\Http\Middleware;
use Closure;
use Auth;
use Redirect;
class RedirectIfNotAdminUser {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
if (Auth::user()->role_id != config('Roles.admin')) {
return Redirect::action('Auth\AuthController@getLogin');
}
return $next($request);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire