To test the registration feature in Fortify, you can create a test that sends a POST request to the registration endpoint with valid data and asserts that the user was created in the database. Here's an example test:
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function testUserCanRegister()
{
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration feature is not enabled.');
}
$response = $this->post('/register', [
'name' => 'John Doe',
'email' => '[email protected]',
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertRedirect('/home');
$this->assertDatabaseHas('users', [
'name' => 'John Doe',
'email' => '[email protected]',
]);
}
}
Note that the test checks if the registration feature is enabled before running the test. If it's not enabled, the test is skipped.
If you need to change the configuration of Fortify in the test runtime, you can use the config() function to set the configuration values. For example, to enable the registration feature, you can add this to the test:
config(['fortify.features' => [Features::registration()]]);
This sets the fortify.features configuration value to an array that contains only the registration feature. You can add this line before the test or inside the test method, depending on your needs.
Hope this helps!