forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for RedirectIfAuthenticated middleware
- Loading branch information
1 parent
b6dd0f5
commit d478860
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...Containers/AppSection/Authentication/Tests/Unit/RedirectIfAuthenticatedMiddlewareTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |