1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RafflesArgentina\ResourceController; |
4
|
|
|
|
5
|
|
|
use Orchestra\Testbench\TestCase; |
6
|
|
|
|
7
|
|
|
class ApiResourceControllerTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
use BaseTest; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @coversNothing |
13
|
|
|
*/ |
14
|
|
|
function testIndexRoute() |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
factory(\RafflesArgentina\ResourceController\Models\User::class, 3)->create(); |
17
|
|
|
|
18
|
|
|
$this->json('GET', '/test3') |
19
|
|
|
->assertStatus(200); |
20
|
|
|
//->assertJsonCount(3, 'data'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @coversNothing |
25
|
|
|
*/ |
26
|
|
|
function testIndexRouteWithUseSoftDeletes() |
27
|
|
|
{ |
28
|
|
|
$users = factory(\RafflesArgentina\ResourceController\Models\User::class, 3)->create(); |
29
|
|
|
foreach ($users as $user) { |
30
|
|
|
$user->delete(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$this->json('GET', '/test4') |
34
|
|
|
->assertStatus(200); |
35
|
|
|
//->assertJsonCount(3, 'data'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @coversNothing |
40
|
|
|
*/ |
41
|
|
|
function testCreateRoute() |
42
|
|
|
{ |
43
|
|
|
$this->json('GET', '/test3/create') |
44
|
|
|
->assertStatus(404); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @coversNothing |
49
|
|
|
*/ |
50
|
|
|
function testStoreRoute() |
51
|
|
|
{ |
52
|
|
|
$this->json('POST', '/test3', ['name' => 'Paula', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
53
|
|
|
->assertStatus(200); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @coversNothing |
58
|
|
|
*/ |
59
|
|
|
function testShowRoute() |
60
|
|
|
{ |
61
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
62
|
|
|
|
63
|
|
|
$this->json('GET', '/test3/'.$user->id) |
64
|
|
|
->assertStatus(200); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @coversNothing |
69
|
|
|
*/ |
70
|
|
|
function testShowRouteWithUseSoftDeletes() |
71
|
|
|
{ |
72
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
73
|
|
|
$user->delete(); |
74
|
|
|
|
75
|
|
|
$this->json('GET', '/test4/'.$user->id) |
76
|
|
|
->assertStatus(200); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @coversNothing |
81
|
|
|
*/ |
82
|
|
|
function testShowRouteWithInexistentModel() |
83
|
|
|
{ |
84
|
|
|
$this->json('GET', '/test3/7')->assertStatus(404); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @coversNothing |
89
|
|
|
*/ |
90
|
|
|
function testEditRoute() |
91
|
|
|
{ |
92
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
93
|
|
|
|
94
|
|
|
$this->json('GET', '/test3/'.$user->id.'/edit') |
95
|
|
|
->assertStatus(404); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @coversNothing |
100
|
|
|
*/ |
101
|
|
|
function testEditRouteWithUseSoftDeletes() |
102
|
|
|
{ |
103
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
104
|
|
|
$user->delete(); |
105
|
|
|
|
106
|
|
|
$this->json('GET', '/test4/'.$user->id.'/edit') |
107
|
|
|
->assertStatus(404); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @coversNothing |
112
|
|
|
*/ |
113
|
|
|
function testEditRouteWithInexistentModel() |
114
|
|
|
{ |
115
|
|
|
$this->json('GET', '/test3/7/edit')->assertStatus(404); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @coversNothing |
120
|
|
|
*/ |
121
|
|
|
function testUpdateRoute() |
122
|
|
|
{ |
123
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
124
|
|
|
|
125
|
|
|
$this->json('PUT', '/test3/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
126
|
|
|
->assertStatus(200); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @coversNothing |
131
|
|
|
*/ |
132
|
|
|
function testUpdateRouteWithUseSoftDeletes() |
133
|
|
|
{ |
134
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
135
|
|
|
$user->delete(); |
136
|
|
|
|
137
|
|
|
$this->json('PUT', '/test4/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
138
|
|
|
->assertStatus(200); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @coversNothing |
143
|
|
|
*/ |
144
|
|
|
function testUpdateRouteWithInexistentModel() |
145
|
|
|
{ |
146
|
|
|
$this->json('PUT', '/test3/7')->assertStatus(404); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @coversNothing |
151
|
|
|
*/ |
152
|
|
|
function testDestroyRoute() |
153
|
|
|
{ |
154
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
155
|
|
|
|
156
|
|
|
$this->json('DELETE', '/test3/'.$user->id) |
157
|
|
|
->assertStatus(200); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @coversNothing |
162
|
|
|
*/ |
163
|
|
|
function testDestroyRouteWithUseSoftDeletes() |
164
|
|
|
{ |
165
|
|
|
$user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
166
|
|
|
$user->delete(); |
167
|
|
|
|
168
|
|
|
$this->json('DELETE', '/test4/'.$user->id) |
169
|
|
|
->assertStatus(200); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @coversNothing |
174
|
|
|
*/ |
175
|
|
|
function testDestroyRouteWithInexistentModel() |
176
|
|
|
{ |
177
|
|
|
$this->json('DELETE', '/test3/7')->assertStatus(404); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.