It should work; what is the actual count? Also, what happens in getFakePatient?
May 9, 2022
3
Level 1
why RefreshDatabase not work for each test?
I use laravel 8 and I wrote some feature test for saving patient in my systems. it seems RefreshDatabase not clear previous test patient records and
$this->assertCount(1, Patient::all()) not worked.
public function testPatientCanSavePatientWithCorrectData()
{
$this->withoutExceptionHandling();
$this->actingAs(User::factory()->create());
$response = $this->postJson(
route('api.web.patient.v1.patients.store'),
$this->getFakePatient()
);
$response->assertSuccessful();
$this->assertCount(1, Patient::all());
}
what is the best practice? I use mysql test database.
<server name="DB_HOST" value="testdb"/> <server name="MYSQL_DATABASE" value="testing"/>
Level 1
@tykus I found it, when we use seeder in Test setUp it's not rollbacked by database transaction
$this->seed(ModelClassSeeder::class)
and we remove it and test passed
Please or to participate in this conversation.