Issue
I am doing a unit test of an API endpoint, I have something like this:
public function testPostService()
{
$response = $this->json('POST', '/api/v1/service',[
"id"=> "someId",
"number" => 123
]);
$response
->assertStatus(201)
->assertJson([
'created' => true,
]);
}
id is a unique value, which leads me to the problem each time I run the tests. I have to either empty the database or change the id value.
Is there any way that the persisted values are only kept during the duration of the test?
My phpunit.xml is the standard
Solution
There's a trait called RefreshDatabase
which refreshes the database after each test made. Just add it to the class of your test cases' class and you're good to go.
Does this solve your problem?
Answered By - Dan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.