8000 Merge branch 'hotfix/0.10.2' · janicerar/laravel-json-api@2503172 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2503172

Browse files
committed
Merge branch 'hotfix/0.10.2'
2 parents fa9ef7c + 924af7f commit 2503172

File tree

2 files changed

+101
-5
lines changed

2 files changed

+101
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## [0.10.2] - 2017-08-25
6+
7+
### Added
8+
- Test assertions to check that resource routes have not been registered.
9+
510
## [0.10.1] - 2017-08-15
611

712
### Fixed

src/Testing/MakesJsonApiRequests.php

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Illuminate\Contracts\Routing\UrlRoutable;
2323
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
2424
use Illuminate\Support\Collection;
25+
use InvalidArgumentException;
2526
use Neomerx\JsonApi\Contracts\Document\DocumentInterface as Keys;
2627
use Neomerx\JsonApi\Contracts\Document\LinkInterface;
2728
use Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface;
@@ -146,7 +147,7 @@ protected function doSearch(array $params = [], array $headers = [])
146147
$params = $this->addDefaultRouteParams($params);
147148
$uri = $this->api()->url()->index($this->resourceType(), $params);
148149

149-
return $this->jsonApi('GET', $uri, [], $headers);
150+
return $this->getJsonApi($uri, [], $headers);
150151
}
151152

152153
/**
@@ -167,6 +168,24 @@ protected function doSearchById($ids, array $params = [], array $headers = [])
167168
return $this->doSearch($params, $headers);
168169
}
169170

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+
170189
/**
171190
* @param array $data
172191
* @param array $params
@@ -178,7 +197,25 @@ protected function doCreate(array $data, array $params = [], array $headers = []
178197
$params = $this->addDefaultRouteParams($params);
179198
$uri = $this->api()->url()->create($this->resourceType(), $params);
180199

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.');
182219
}
183220

184221
/**
@@ -192,7 +229,25 @@ protected function doRead($resourceId, array $params = [], array $headers = [])
192229
$params = $this->addDefaultRouteParams($params);
193230
$uri = $this->api()->url()->read($this->resourceType(), $resourceId, $params);
194231

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.');
196251
}
197252

198253
/**
@@ -212,7 +267,25 @@ protected function doUpdate(array $data, array $params = [], array $headers = []
212267
$params = $this->addDefaultRouteParams($params);
213268
$uri = $this->api()->url()->update($this->resourceType(), $id, $params);
214269

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.');
216289
}
217290

218291
/**
@@ -226,7 +299,25 @@ protected function doDelete($resourceId, array $params = [], array $headers = []
226299
$params = $this->addDefaultRouteParams($params);
227300
$uri = $this->api()->url()->delete($this->resourceType(), $resourceId, $params);
228301

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.');
230321
}
231322

232323
/**

0 commit comments

Comments
 (0)
0