Skip to content

Commit

Permalink
add test for RedirectIfAuthenticated middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Oct 3, 2021
1 parent b6dd0f5 commit d478860
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Containers\AppSection\Authentication\Tests\Unit;

use App\Containers\AppSection\Authentication\Middlewares\RedirectIfAuthenticated;
use App\Containers\AppSection\Authentication\Tests\TestCase;
use App\Containers\AppSection\User\Models\User;
use App\Ship\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Request;

/**
* Class RedirectIfAuthenticatedMiddlewareTest.
*
* @group authentication
* @group unit
*/
class RedirectIfAuthenticatedMiddlewareTest extends TestCase
{
public function testRedirectIfAuthenticated(): void
{
$user = User::factory()->make();
$this->actingAs($user, 'web');

$request = Request::create(RouteServiceProvider::LOGIN);

$middleware = new RedirectIfAuthenticated();

$response = $middleware->handle($request, function ($req) {
$this->assertInstanceOf(Request::class, $req);
});

$this->assertEquals($response->getStatusCode(), 302);
}
}

0 comments on commit d478860

Please sign in to comment.