22
22
use Illuminate \Contracts \Routing \UrlRoutable ;
23
23
use Illuminate \Foundation \Testing \Concerns \MakesHttpRequests ;
24
24
use Illuminate \Support \Collection ;
25
+ use InvalidArgumentException ;
25
26
use Neomerx \JsonApi \Contracts \Document \DocumentInterface as Keys ;
26
27
use Neomerx \JsonApi \Contracts \Document \LinkInterface ;
27
28
use Neomerx \JsonApi \Contracts \Http \Headers \MediaTypeInterface ;
@@ -146,7 +147,7 @@ protected function doSearch(array $params = [], array $headers = [])
146
147
$ params = $ this ->addDefaultRouteParams ($ params );
147
148
$ uri = $ this ->api ()->url ()->index ($ this ->resourceType (), $ params );
148
149
149
- return $ this ->jsonApi ( ' GET ' , $ uri , [], $ headers );
150
+ return $ this ->getJsonApi ( $ uri , [], $ headers );
150
151
}
151
152
152
153
/**
@@ -167,6 +168,24 @@ protected function doSearchById($ids, array $params = [], array $headers = [])
167
168
return $ this ->doSearch ($ params , $ headers );
168
169
}
169
170
171
+ /**
172
+ * Assert that the resource's search (index) route has not been registered.
173
+ *
174
+ * @return void
175
+ */
176
+ protected function assertCannotSearch ()
177
+ {
178
+ $ searchable = true ;
179
+
180
+ try {
181
+ $ this ->api ()->url ()->index ($ this ->resourceType (), $ this ->addDefaultRouteParams ([]));
182
+ } catch (InvalidArgumentException $ ex ) {
183
+ $ searchable = false ;
184
+ }
185
+
186
+ $ this ->assertFalse ($ searchable , 'Resource search route exists. ' );
187
+ }
188
+
170
189
/**
171
190
* @param array $data
172
191
* @param array $params
@@ -178,7 +197,25 @@ protected function doCreate(array $data, array $params = [], array $headers = []
178
197
$ params = $ this ->addDefaultRouteParams ($ params );
179
198
$ uri = $ this ->api ()->url ()->create ($ this ->resourceType (), $ params );
180
199
181
- return $ this ->jsonApi ('POST ' , $ uri , ['data ' => $ data ], $ headers );
200
+ return $ this ->postJsonApi ($ uri , ['data ' => $ data ], $ headers );
201
+ }
202
+
203
+ /**
204
+ * Assert that the resource's create route has not been registered.
205
+ *
206
+ * @return void
207
+ */
208
+ protected function assertCannotCreate ()
209
+ {
210
+ $ creatable = true ;
211
+
212
+ try {
213
+ $ this ->api ()->url ()->create ($ this ->resourceType (), $ this ->addDefaultRouteParams ([]));
214
+ } catch (InvalidArgumentException $ ex ) {
215
+ $ creatable = false ;
216
+ }
217
+
218
+ $ this ->assertFalse ($ creatable , 'Resource create route exists. ' );
182
219
}
183
220
184
221
/**
@@ -192,7 +229,25 @@ protected function doRead($resourceId, array $params = [], array $headers = [])
192
229
$ params = $ this ->addDefaultRouteParams ($ params );
193
230
$ uri = $ this ->api ()->url ()->read ($ this ->resourceType (), $ resourceId , $ params );
194
231
195
- return $ this ->jsonApi ('GET ' , $ uri , $ headers );
232
+ return $ this ->getJsonApi ($ uri , [], $ headers );
233
+ }
234
+
235
+ /**
236
+ * Assert that the resource's read route has not been registered.
237
+ *
238
+ * @return void
239
+ */
240
+ protected function assertCannotRead ()
241
+ {
242
+ $ readable = true ;
243
+
244
+ try {
245
+ $ this ->api ()->url ()->read ($ this ->resourceType (), '1 ' , $ this ->addDefaultRouteParams ([]));
246
+ } catch (InvalidArgumentException $ ex ) {
247
+ $ readable = false ;
248
+ }
249
+
250
+ $ this ->assertFalse ($ readable , 'Resource read route exists. ' );
196
251
}
197
252
198
253
/**
@@ -212,7 +267,25 @@ protected function doUpdate(array $data, array $params = [], array $headers = []
212
267
$ params = $ this ->addDefaultRouteParams ($ params );
213
268
$ uri = $ this ->api ()->url ()->update ($ this ->resourceType (), $ id , $ params );
214
269
215
- return $ this ->jsonApi ('PATCH ' , $ uri , ['data ' => $ data ], $ headers );
270
+ return $ this ->patchJsonApi ($ uri , ['data ' => $ data ], $ headers );
271
+ }
272
+
273
+ /**
274
+ * Assert that the resource's update route has not been registered.
275
+ *
276
+ * @return void
277
+ */
278
+ protected function assertCannotUpdate ()
279
+ {
280
+ $ exists = true ;
281
+
282
+ try {
283
+ $ this ->api ()->url ()->update ($ this ->resourceType (), '1 ' , $ this ->addDefaultRouteParams ([]));
284
+ } catch (InvalidArgumentException $ ex ) {
285
+ $ exists = false ;
286
+ }
287
+
288
+ $ this ->assertFalse ($ exists , 'Resource update route exists. ' );
216
289
}
217
290
218
291
/**
@@ -226,7 +299,25 @@ protected function doDelete($resourceId, array $params = [], array $headers = []
226
299
$ params = $ this ->addDefaultRouteParams ($ params );
227
300
$ uri = $ this ->api ()->url ()->delete ($ this ->resourceType (), $ resourceId , $ params );
228
301
229
- return $ this ->jsonApi ('DELETE ' , $ uri , [], $ headers );
302
+ return $ this ->deleteJsonApi ($ uri , [], $ headers );
303
+ }
304
+
305
+ /**
306
+ * Assert that the resource's delete route has not been registered.
307
+ *
308
+ * @return void
309
+ */
310
+ protected function assertCannotDelete ()
311
+ {
312
+ $ deletable = true ;
313
+
314
+ try {
315
+ $ this ->api ()->url ()->delete ($ this ->resourceType (), '1 ' , $ this ->addDefaultRouteParams ([]));
316
+ } catch (InvalidArgumentException $ ex ) {
317
+ $ deletable = false ;
318
+ }
319
+
320
+ $ this ->assertFalse ($ deletable , 'Resource delete route exists. ' );
230
321
}
231
322
232
323
/**
0 commit comments