-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.stub
executable file
·59 lines (45 loc) · 1.68 KB
/
test.stub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace {{ namespace }};
use Tests\TestCase;
class {{ class }} extends TestCase
{
private $path = '/api/{{ class }}'; //@todo: set correct path
private $model = \App\Models\{{ class }}::class; //@todo: set correct model class
private $table = '{{ class }}'; //@todo: set correct table
public function test_create_{{ class }}()
{
$data = $this->model::factory()->make();
$this->postJson($this->path, ['data' => $data->toArray()])
->assertCreated();
$this->assertDatabaseHas($this->table, $data->toArray());
}
public function test_show_{{ class }}()
{
$data = $this->model::factory()->create();
$response = $this->getJson($this->path . '/' . $data->getRouteKey());
$response->assertOk();
$response->assertJsonFragment($data->toArray());
}
public function test_update_{{ class }}()
{
$data = $this->model::factory()->create();
$newData = $this->model::factory()->make();
$response = $this->putJson($this->path . '/' . $data->getRouteKey(), ['data' => $newData->toArray()]);
$response->assertOk();
$response->assertJsonFragment($newData->toArray());
}
public function test_list_{{ class }}()
{
$this->model::factory()->count(10)->create();
$response = $this->get($this->path);
$response->assertOk();
$response->assertJsonCount(10, 'data');
}
public function test_delete_{{ class }}()
{
$data = $this->model::factory()->create();
$this->delete($this->path . '/' . $data->getRouteKey())
->assertNoContent();
$this->assertDatabaseCount($this->table, 0);
}
}