1 | <?php |
||
2 | |||
3 | namespace RafflesArgentina\ResourceController; |
||
4 | |||
5 | use Orchestra\Testbench\TestCase; |
||
6 | |||
7 | class ResourceControllerTest extends TestCase |
||
8 | { |
||
9 | use BaseTest; |
||
10 | |||
11 | /** |
||
12 | * @coversNothing |
||
13 | */ |
||
14 | function testIndexRoute() |
||
0 ignored issues
–
show
|
|||
15 | { |
||
16 | factory(\RafflesArgentina\ResourceController\Models\User::class, 3)->create(); |
||
17 | |||
18 | $this->get('/test') |
||
19 | ->assertViewIs('test.index') |
||
20 | ->assertViewHas('items') |
||
21 | ->assertStatus(200); |
||
22 | |||
23 | $this->json('GET', '/test') |
||
24 | ->assertStatus(200); |
||
25 | //->assertJsonCount(3, 'data'); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @coversNothing |
||
30 | */ |
||
31 | function testIndexRouteWithUseSoftDeletes() |
||
32 | { |
||
33 | $users = factory(\RafflesArgentina\ResourceController\Models\User::class, 3)->create(); |
||
34 | foreach ($users as $user) { |
||
35 | $user->delete(); |
||
36 | } |
||
37 | |||
38 | $this->get('/test2') |
||
39 | ->assertViewIs('test.index') |
||
40 | ->assertViewHas('items') |
||
41 | ->assertStatus(200); |
||
42 | |||
43 | $this->json('GET', '/test2') |
||
44 | ->assertStatus(200); |
||
45 | //->assertJsonCount(3, 'data'); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @coversNothing |
||
50 | */ |
||
51 | function testCreateRoute() |
||
52 | { |
||
53 | $this->get('/test/create') |
||
54 | ->assertViewIs('test.create') |
||
55 | ->assertViewHas('model') |
||
56 | ->assertStatus(200); |
||
57 | |||
58 | $this->json('GET', '/test/create') |
||
59 | ->assertStatus(404); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @coversNothing |
||
64 | */ |
||
65 | function testStoreRoute() |
||
66 | { |
||
67 | $this->post('/test', ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
68 | ->assertRedirect('/test') |
||
69 | ->assertSessionHas('rafflesargentina.status.success'); |
||
70 | |||
71 | $this->json('POST', '/test', ['name' => 'Paula', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
72 | ->assertStatus(200); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @coversNothing |
||
77 | */ |
||
78 | function testShowRoute() |
||
79 | { |
||
80 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
81 | |||
82 | $this->get('/test/'.$user->id) |
||
83 | ->assertViewIs('test.show') |
||
84 | ->assertViewHas('model') |
||
85 | ->assertStatus(200); |
||
86 | |||
87 | $this->json('GET', '/test/'.$user->id) |
||
88 | ->assertStatus(200); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @coversNothing |
||
93 | */ |
||
94 | function testShowRouteWithUseSoftDeletes() |
||
95 | { |
||
96 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
97 | $user->delete(); |
||
98 | |||
99 | $this->get('/test2/'.$user->id) |
||
100 | ->assertViewIs('test.show') |
||
101 | ->assertViewHas('model') |
||
102 | ->assertStatus(200); |
||
103 | |||
104 | $this->json('GET', '/test2/'.$user->id) |
||
105 | ->assertStatus(200); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @coversNothing |
||
110 | */ |
||
111 | function testShowRouteWithInexistentModel() |
||
112 | { |
||
113 | $this->get('/test/7')->assertStatus(404); |
||
114 | |||
115 | $this->json('GET', '/test/7')->assertStatus(404); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @coversNothing |
||
120 | */ |
||
121 | function testEditRoute() |
||
122 | { |
||
123 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
124 | |||
125 | $this->get('/test/'.$user->id.'/edit') |
||
126 | ->assertViewIs('test.edit') |
||
127 | ->assertViewHas('model') |
||
128 | ->assertStatus(200); |
||
129 | |||
130 | $this->json('GET', '/test/'.$user->id.'/edit') |
||
131 | ->assertStatus(404); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @coversNothing |
||
136 | */ |
||
137 | function testEditRouteWithUseSoftDeletes() |
||
138 | { |
||
139 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
140 | $user->delete(); |
||
141 | |||
142 | $this->get('/test2/'.$user->id.'/edit') |
||
143 | ->assertViewIs('test.edit') |
||
144 | ->assertViewHas('model') |
||
145 | ->assertStatus(200); |
||
146 | |||
147 | $this->json('GET', '/test2/'.$user->id.'/edit') |
||
148 | ->assertStatus(404); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @coversNothing |
||
153 | */ |
||
154 | function testEditRouteWithInexistentModel() |
||
155 | { |
||
156 | $this->get('/test/7/edit')->assertStatus(404); |
||
157 | |||
158 | $this->json('GET', '/test/7/edit')->assertStatus(404); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @coversNothing |
||
163 | */ |
||
164 | function testUpdateRoute() |
||
165 | { |
||
166 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
167 | |||
168 | $this->put('/test/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
169 | ->assertRedirect('/test') |
||
170 | ->assertStatus(302) |
||
171 | ->assertSessionHas('rafflesargentina.status.success'); |
||
172 | |||
173 | $this->json('PUT', '/test/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
174 | ->assertStatus(200); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @coversNothing |
||
179 | */ |
||
180 | function testUpdateRouteWithUseSoftDeletes() |
||
181 | { |
||
182 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
183 | $user->delete(); |
||
184 | |||
185 | $this->put('/test2/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
186 | ->assertRedirect('/test') |
||
187 | ->assertStatus(302) |
||
188 | ->assertSessionHas('rafflesargentina.status.success'); |
||
189 | |||
190 | $this->json('PUT', '/test2/'.$user->id, ['name' => 'Mario', 'email' => '[email protected]', 'password' => bcrypt(str_random())]) |
||
191 | ->assertStatus(200); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @coversNothing |
||
196 | */ |
||
197 | function testUpdateRouteWithInexistentModel() |
||
198 | { |
||
199 | $this->put('/test/7')->assertStatus(404); |
||
200 | |||
201 | $this->json('PUT', '/test/7')->assertStatus(404); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @coversNothing |
||
206 | */ |
||
207 | function testDestroyRoute() |
||
208 | { |
||
209 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
210 | $this->delete('/test/'.$user->id) |
||
211 | ->assertRedirect('/test') |
||
212 | ->assertStatus(302); |
||
213 | |||
214 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
215 | $this->json('DELETE', '/test/'.$user->id) |
||
216 | ->assertStatus(200); |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @coversNothing |
||
221 | */ |
||
222 | function testDestroyRouteWithUseSoftDeletes() |
||
223 | { |
||
224 | $user = factory(\RafflesArgentina\ResourceController\Models\User::class)->create(); |
||
225 | $user->delete(); |
||
226 | |||
227 | $this->delete('/test2/'.$user->id) |
||
228 | ->assertRedirect('/test') |
||
229 | ->assertStatus(302); |
||
230 | |||
231 | $this->json('DELETE', '/test2/'.$user->id) |
||
232 | ->assertStatus(200); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @coversNothing |
||
237 | */ |
||
238 | function testDestroyRouteWithInexistentModel() |
||
239 | { |
||
240 | $this->delete('/test/7')->assertStatus(404); |
||
241 | |||
242 | $this->json('DELETE', '/test/7')->assertStatus(404); |
||
243 | } |
||
244 | } |
||
245 |
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.