45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use Laravel\Fortify\Features;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config([
|
|
'app.debug' => false,
|
|
'session.driver' => 'array',
|
|
'cache.default' => 'array',
|
|
'mail.default' => 'array',
|
|
]);
|
|
|
|
$this->withoutMiddleware(ValidateCsrfToken::class);
|
|
}
|
|
|
|
/**
|
|
* POST with a real CSRF token for Fortify/web form tests.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
protected function csrfPost(string $uri, array $data = []): \Illuminate\Testing\TestResponse
|
|
{
|
|
$token = 'test-csrf-token';
|
|
|
|
return $this->withSession(['_token' => $token])
|
|
->post($uri, ['_token' => $token, ...$data]);
|
|
}
|
|
|
|
protected function skipUnlessFortifyHas(string $feature, ?string $message = null): void
|
|
{
|
|
if (! Features::enabled($feature)) {
|
|
$this->markTestSkipped($message ?? "Fortify feature [{$feature}] is not enabled.");
|
|
}
|
|
}
|
|
}
|