Skip to content

Instantly share code, notes, and snippets.

@sagormax
Last active October 8, 2018 02:12
Show Gist options
  • Save sagormax/5abe8391a6bf66375274f71335c4945f to your computer and use it in GitHub Desktop.
Save sagormax/5abe8391a6bf66375274f71335c4945f to your computer and use it in GitHub Desktop.
PHPUnit Test Case Example
<?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