|
2 | 2 |
|
3 | 3 | ## 3.x to 4.0 |
4 | 4 |
|
| 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 | + |
5 | 14 | ### PHP 8.1 |
6 | 15 |
|
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 |
8 | 17 | methods for internal interfaces. This is unlikely to break your application, unless you have extended one of our classes |
9 | 18 | and overridden an internal method. |
10 | 19 |
|
| 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 | +
|
11 | 159 | ## 2.x to 3.0 |
12 | 160 |
|
13 | 161 | ### Validators |
|
0 commit comments