@ranx99
As this is a very common test for me, I have had added it to a trait RestrictUnverifiedEmailAccessViaGetRequests which I then include in the required tests
(I have similar ones for Post, Put and Delete), and this the trait:
namespace Tests\Feature\Traits;
use App\User;
trait RestrictUnverifiedEmailAccessViaGetRequests
{
/** @test */
public function users_with_unverified_emails_cannot_access_via_get()
{
$user = factory(User::class)
->states('unverified')
->create();
$this->actingAs($user);
foreach ($this->routesToTest['get'] as $route => $params) {
$this->get(route($route, $params))
->assertRedirect(route('verification.notice'));
}
}
}
Then in my tests, I just have to use the traits, and setup the routes to test, eg:
class DashboardTest extends TestCase
{
use RefreshDatabase;
use RestrictGuestAccessViaGetRequests;
protected $routesToTest = [
'get' => [
'dashboard' => [],
],
];
}
(this is if you used named routes, but you could easily modify)