Last active
October 8, 2018 02:12
-
-
Save sagormax/5abe8391a6bf66375274f71335c4945f to your computer and use it in GitHub Desktop.
PHPUnit Test Case Example
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 | |
$user = factory(User::class)->create([ | |
'email' => '[email protected]', | |
'password' => bcrypt('toptal123'), | |
]); | |
$payload = ['email' => '[email protected]', 'password' => 'toptal123']; | |
// 1 | |
$this->json('POST', 'api/login', $payload) | |
->assertStatus(200) | |
->assertJsonStructure([ | |
'data' => [ | |
'id', | |
'name', | |
'email', | |
'created_at', | |
'updated_at', | |
'api_token', | |
], | |
]); | |
// 2 | |
$this->assertArrayHasKey('nickname', $data); | |
// 3 | |
$this->seeJsonStructure([ | |
'data' => ['*' => | |
[ | |
'product_name', | |
'product_description', | |
'created_at', | |
'updated_at', | |
'links' | |
] | |
], | |
'meta' => [ | |
'*' => [ | |
'total', | |
'count', | |
'per_page', | |
'current_page', | |
'total_pages', | |
'links', | |
] | |
] | |
]); | |
// 4 | |
$this->seeJsonStructure( | |
['data' => | |
[ | |
'product_name', | |
'product_description', | |
'created_at', | |
'updated_at', | |
'links' | |
] | |
] | |
); | |
// 5 | |
$this->assertFalse($data); | |
// 6 | |
$this->assertNotNull($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment