Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created February 10, 2020 08:01
Show Gist options
  • Select an option

  • Save devmsh/67f0542240514c02fd2129843d0fc484 to your computer and use it in GitHub Desktop.

Select an option

Save devmsh/67f0542240514c02fd2129843d0fc484 to your computer and use it in GitHub Desktop.
Write better Laravel tests 1
<?php
public function test_users_can_get_their_categories_list()
{
factory(Category::class, 5)->create();
$user = factory(User::class)->create();
Passport::actingAs($user);
$response = $this->get('api/categories');
$response->assertSuccessful();
$response->assertJsonCount(5);
$response->assertJsonStructure([
[
'id',
'name',
'type',
],
]);
foreach ($response->json() as $category) {
$this->assertEquals($user->id,$category['user_id']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment