Hi all, I'm trying to understand which is the best practice to test an API with PHPUnit under Laravel.
$user = factory(User::class)->create(); $response = $this->actingAs($user) ->get('/xyz/aaa/bbb/ccc'); $response->assertStatus(200);
My /xyz route is under auth, so I need to access if acting as an authenticated user.
Creating a new user is the answer (I think) but if I launch 10 times the test, I'll create 10 users (of course !)
Which is the right (or the best) way to create a "temporary" user to test my API ?
Should I leverage on SetUp and TearDown methods ? Or there's a better way ?
Thanks in Advance FabioG
Please sign in or create an account to participate in this conversation.
Reply to
Use Markdown with GitHub-flavored code blocks.
There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!
Get Started
Temporary User for testing
Hi all, I'm trying to understand which is the best practice to test an API with PHPUnit under Laravel.
My /xyz route is under auth, so I need to access if acting as an authenticated user.
Creating a new user is the answer (I think) but if I launch 10 times the test, I'll create 10 users (of course !)
Which is the right (or the best) way to create a "temporary" user to test my API ?
Should I leverage on SetUp and TearDown methods ? Or there's a better way ?
Thanks in Advance FabioG