Created
February 10, 2020 08:01
-
-
Save devmsh/67f0542240514c02fd2129843d0fc484 to your computer and use it in GitHub Desktop.
Write better Laravel tests 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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