@bobbybouwmann no worries :)
@bjones2015
The thing is with this I'm not trying to test the controller, but rather the middleware.
In this case, it is really simple to test, you don't need to mock any thing at all, since you are only interested in testing the functionality of the middleware.
I'm not concerned about the controller response.
IMHO, yes you do. Let me show you a simple example of testing the auth middleware that Laravel provides out of the box.
class ExampleTest extends TestCase
{
public function test_admin_can_access()
{
$this->defineRoute();
$user = User::first();
$this->be($user);
$this->get('admin-page');
$this->assertResponseStatus(200);
}
public function test_guest_cannot_access()
{
$this->defineRoute();
$this->get('admin-page');
//expecting it to redirect us to login page.
$this->assertResponseStatus(302);
}
protected function defineRoute()
{
$this->app['router']->get(
'admin-page',
[
'middleware' => 'auth',
function() {
return 'this is admin page';
}
]
);
}
}
The idea here is to keep things simple. This is the freedom that functional tests give us so embrace it :).
Usman.