Skip to content

Commit 68d5489

Browse files
committed
[Refactor] Use the laravel-json-api/testing dependency
1 parent d714aa1 commit 68d5489

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2463
-2190
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ All notable changes to this project will be documented in this file. This projec
1717
- Package now depends on our fork of the Neomerx JSON:API package - `laravel-json-api/neomerx-json-api`. This is a
1818
non-breaking change.
1919

20+
### Removed
21+
22+
- **BREAKING** Removed the following classes from the `CloudCreativity\LaravelJsonApi\Testing` namespace. You must
23+
use classes (with the same names) from the `LaravelJsonApi\Testing` namespace, after installing the
24+
`laravel-json-api/testing` package as a dev dependency. Refer to the upgrade guide for details. Classes/traits removed
25+
are:
26+
- `MakesJsonApiRequests`
27+
- `TestBuilder`
28+
- `TestResponse`
29+
2030
## Unreleased
2131

2232
### Changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"ext-sqlite3": "*",
3535
"cloudcreativity/json-api-testing": "^4.0",
3636
"guzzlehttp/guzzle": "^7.0",
37+
"laravel-json-api/testing": "^1.1",
3738
"laravel/legacy-factories": "^1.0.4",
3839
"laravel/ui": "^3.0",
3940
"mockery/mockery": "^1.1",

docs/upgrade.md

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,160 @@
22

33
## 3.x to 4.0
44

5+
To upgrade, run the following Composer commands:
6+
7+
```bash
8+
composer remove cloudcreativity/json-api-testing --dev
9+
composer require cloudcreativity/laravel-json-api:^4.0 --no-update
10+
composer require laravel-json-api/testing:^1.1 --no-update
11+
composer up cloudcreativity/* laravel-json-api/*
12+
```
13+
514
### PHP 8.1
615

7-
To remove deprecation messages from PHP 8.1, we've added return types of `#[\ReturnTypeWillChange]` annotations to
16+
To remove deprecation messages from PHP 8.1, we've added return types or `#[\ReturnTypeWillChange]` annotations to
817
methods for internal interfaces. This is unlikely to break your application, unless you have extended one of our classes
918
and overridden an internal method.
1019

20+
### Testing
21+
22+
We are switching to using the `laravel-json-api/testing` package. This will help in the future with upgrading to the
23+
new `laravel-json-api/laravel` package, because it will mean when you upgrade your tests should continue to work
24+
without modifications. I.e. having a great test suite for your JSON:API functionality will help you safely upgrade in
25+
the future.
26+
27+
The `laravel-json-api/testing` dependency uses the `cloudcreativity/json-api-testing` package, which is what you have
28+
been using up until now. It's just a more recent version, so there are a few changes to implement when upgrading.
29+
30+
The new testing package is fully
31+
[documented on the Laravel JSON:API site](https://laraveljsonapi.io/docs/1.0/testing/) so we recommend you take a look
32+
at that if you get stuck when upgrading.
33+
34+
#### Test Case
35+
36+
In the test case where you're importing `MakesJsonApiRequests`, change the `use` statement from this:
37+
38+
```php
39+
use CloudCreativity\LaravelJsonApi\Testing\MakesJsonApiRequests;
40+
```
41+
42+
to this:
43+
44+
```php
45+
use LaravelJsonApi\Testing\MakesJsonApiRequests;
46+
```
47+
48+
#### Test Response
49+
50+
If anywhere in your application you have type-hinted our specific `TestResponse` you will need to change the `use`
51+
statement. (Note that most applications won't have type-hinted the `TestResponse` anywhere.)
52+
53+
Previously:
54+
55+
```php
56+
use CloudCreativity\LaravelJsonApi\Testing\TestResponse;
57+
```
58+
59+
It now needs to be:
60+
61+
```php
62+
use LaravelJsonApi\Testing\TestResponse;
63+
```
64+
65+
#### Test Actions
66+
67+
The following test actions have been deprecated for some time and have now been removed. This is because these helper
68+
methods used the JSON:API implementation internally, which was potentially risky as the JSON:API implementation itself
69+
is the subject of the tests. These are the methods:
70+
71+
- `doSearch()`
72+
- `doSearchById()`
73+
- `doCreate()`
74+
- `doRead()`
75+
- `doUpdate()`
76+
- `doDelete()`
77+
- `doReadRelated()`
78+
- `doReadRelationship()`
79+
- `doReplaceRelationship()`
80+
- `doAddToRelationship()`
81+
- `doRemoveFromRelationship()`
82+
83+
Here are example replacements:
84+
85+
```php
86+
// doSearch()
87+
$response = $this->jsonApi('posts')->get('/api/v1/posts');
88+
89+
// doSearchById()
90+
$response = $this
91+
->jsonApi('posts')
92+
->filter(['id' => $posts])
93+
->get('/api/v1/posts');
94+
95+
// doCreate()
96+
$response = $this
97+
->jsonApi('posts')
98+
->withData($data)
99+
->post('/api/v1/posts');
100+
101+
// doRead()
102+
$response = $this
103+
->jsonApi('posts')
104+
->get(url('/api/v1/posts', $post));
105+
106+
// doUpdate()
107+
$response = $this
108+
->jsonApi('posts')
109+
->withData($data)
110+
->patch(url('/api/v1/posts', $post));
111+
112+
// doDelete()
113+
$response = $this
114+
->jsonApi('posts')
115+
->delete(url('/api/v1/posts', $post));
116+
117+
// doReadRelated()
118+
$response = $this
119+
->jsonApi('comments')
120+
->get(url('/api/v1/posts', [$post, 'comments']));
121+
122+
// doReadRelationship()
123+
$response = $this
124+
->jsonApi('comments')
125+
->get(url('/api/v1/posts', [$post, 'relationships', 'comments']));
126+
127+
// doReplaceRelationship()
128+
$response = $this
129+
->jsonApi('comments')
130+
->withData($data)
131+
->patch(url('/api/v1/posts', [$post, 'relationships', 'comments']));
132+
133+
// doAddToRelationship()
134+
$response = $this
135+
->jsonApi('comments')
136+
->withData($data)
137+
->post(url('/api/v1/posts', [$post, 'relationships', 'comments']));
138+
139+
// doRemoveFromRelationship()
140+
$response = $this
141+
->jsonApi('comments')
142+
->withData($data)
143+
->delete(url('/api/v1/posts', [$post, 'relationships', 'comments']));
144+
```
145+
146+
> Note in all the above we use `withData()` to set the data for the request. Previously there was a `data` method, which
147+
> has been removed.
148+
149+
Also, the following HTTP verb JSON:API methods have been removed:
150+
151+
- `getJsonApi` - use `$this->jsonApi('posts')->get($url)`
152+
- `postJsonApi` - use `$this->jsonApi('posts')->withData($data)->post($url)`
153+
- `patchJsonApi` - use `$this->jsonApi('posts')->withData($data)->patch($url)`
154+
- `deleteJsonApi` - use `$this->jsonApi('posts')->withData($data)->delete($url)`
155+
156+
> For info, everything has been moved to the test builder that's returned by the `jsonApi()` method, so that we can
157+
> avoid collisions with any methods that Laravel might.
158+
11159
## 2.x to 3.0
12160

13161
### Validators

0 commit comments

Comments
 (0)