I have the following test:
public function testExample()
{
$user = factory(User::class)->create();
$response = $this->actingAs($user,'api')->json('POST', 'api/rangos?api_token='.$user->api_token,
[
"denominacion"=>"Visitante",
"nivel"=>"1"
]
);
$response->assertStatus(201);
$response->assertJsonStructure([
"id",
"denominacion",
"nivel",
"miembros",
"updated_at",
"created_at"
]);
}
The function I'm unit testing is as follows:
public function store(Request $request){
$data=new Rango($request->all());
$data->save();
return response()->json($data->load("miembros"),201);
}
The unit test passes successfully, the problem is that when executing the test the data is stored in the database. ie if I run the test 10 times the data is logged 10 times and I want to prevent that from happening.
How do I get it to pass the test without the data being permanently recorded in the database?
Edition
I already tried to do it with the trait RefreshDatabase
and what happens with RefreshDatabase is that it deletes any other data inside my database, that is, it cleans the entire database, and I don't want that either.