generated from Soyhuce/package-skeleton-laravel
-
-
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.
- Loading branch information
1 parent
35a734f
commit 80c1616
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
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
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,12 @@ | ||
/* @@covers \{{ $covered }} */ | ||
|
||
use {{ $classFqcn }}; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
it('handles the request', function(): void { | ||
Route::get('test', fn() => 'ok') | ||
->middleware({{ $classBasename }}::class); | ||
|
||
$this->get('test') | ||
->assertOk(); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/Domains/Test/UnitTestGenerators/MiddlewareTestGenerator.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,53 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\Somake\Domains\Test\UnitTestGenerators; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use ReflectionClass; | ||
use ReflectionNamedType; | ||
use Soyhuce\Somake\Contracts\UnitTestGenerator; | ||
use function count; | ||
|
||
/** | ||
* @implements \Soyhuce\Somake\Contracts\UnitTestGenerator<mixed> | ||
*/ | ||
class MiddlewareTestGenerator implements UnitTestGenerator | ||
{ | ||
public static function shouldHandle(string $class): bool | ||
{ | ||
if (!class_exists($class)) { | ||
return false; | ||
} | ||
|
||
$reflectionClass = new ReflectionClass($class); | ||
if (!$reflectionClass->hasMethod('handle')) { | ||
return false; | ||
} | ||
|
||
$parameters = $reflectionClass->getMethod('handle')->getParameters(); | ||
if (count($parameters) < 2) { | ||
return false; | ||
} | ||
|
||
if (!$parameters[0]->getType() instanceof ReflectionNamedType || $parameters[0]->getType()->getName() !== Request::class) { | ||
return false; | ||
} | ||
|
||
if (!$parameters[1]->getType() instanceof ReflectionNamedType || $parameters[1]->getType()->getName() !== Closure::class) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function view(): string | ||
{ | ||
return 'test-unit-middleware'; | ||
} | ||
|
||
public function data(string $class): array | ||
{ | ||
return []; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
test-laravel/tests/Unit/Support/Http/Middleware/PreventRequestsDuringMaintenanceTest.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,6 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* @covers \Support\Http\Middleware\PreventRequestsDuringMaintenance */ | ||
|
||
it('is successful', function (): void { | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
...apshots__/files/TestCommandTest__it_creates_correctly_the_unit_test_for_middleware__1.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,14 @@ | ||
<?php | ||
|
||
/* @covers \Support\Http\Middleware\RedirectIfAuthenticated */ | ||
|
||
use Support\Http\Middleware\RedirectIfAuthenticated; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
it('handles the request', function(): void { | ||
Route::get('test', fn() => 'ok') | ||
->middleware(RedirectIfAuthenticated::class); | ||
|
||
$this->get('test') | ||
->assertOk(); | ||
}); |