$ cp .env.example .env.testing
$ php artisan key:generate –env=testing
// test用のDB接続
$ vi .env.testing
$ rm ./tests/Feature/ExampleTest.php
$ rm ./tests/Unit/ExampleTest.php

app/Actions/Fortify/CreateNewUser.php
return User::create([
'name' => $input['name'],
'company' => $input['company'],
'role_id' => 1,
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
CreateNewUser.phpと同じようなことを書いていく
$ php artisan make:test UserRegisterTest
tests/Feature/UserRegisterTest.php
public function testUserRegister()
{
$email = 'hogehoge@gmail.com';
$this->post(route('register'), [
'name' => 'testuser',
'company' => 'test company',
'email' => $email,
'password' => 'password',
'password_confirmation' => 'password'
])
->assertStatus(302);
$this->assertDatabaseHas('users', ['email' => $email]);
}
$ vendor/bin/phpunit –testdox
PHPUnit 9.4.3 by Sebastian Bergmann and contributors.
User Register (Tests\Feature\UserRegister)
✔ User register
Time: 00:00.354, Memory: 26.00 MB
OK (1 test, 2 assertions)
なるほど、わかったようなわかってないようなw