Skip to content

Commit 0a1fb4b

Browse files
Upgrade to API Platform (#174)
* Upgraded to APIP4 - except upload put * Finish upgrade, remove PUT request support by default * CS Fixes * Remove 8.3 support * Fix text for info.version regex allow hyphens * Fix route voter * Fix for next release of voters in symfony * Fix updates to security contracts of voter and UserChecker
1 parent dccc2a4 commit 0a1fb4b

24 files changed

+70
-59
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
strategy:
5252
matrix:
5353
php:
54-
- '8.3'
5554
- '8.4'
5655
symfony:
5756
- '7.3'
@@ -150,7 +149,6 @@ jobs:
150149
strategy:
151150
matrix:
152151
php:
153-
- '8.3'
154152
- '8.4'
155153
symfony:
156154
- '7.3'

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=8.3",
21+
"php": ">=8.4",
2222
"ext-exif": "*",
2323
"ext-fileinfo": "*",
2424
"ext-json": "*",
2525
"ext-pdo": "*",
2626
"ext-simplexml": "*",
27-
"api-platform/core": "^3.3.1 || 3.3.x-dev",
27+
"api-platform/core": "^4.2",
2828
"cocur/slugify": "^4.1",
2929
"doctrine/annotations": "^1.7.0",
3030
"doctrine/dbal": "^3.4",
@@ -136,7 +136,6 @@
136136
}
137137
},
138138
"conflict": {
139-
"api-platform/core": "dev-main",
140139
"willdurand/negotiation": "^2",
141140
"symfony/serializer": "<=6.1.2",
142141
"symfony/var-exporter": "<6.1",

features/bootstrap/DoctrineContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Silverback\ApiComponentsBundle\Features\Bootstrap;
1515

16-
use ApiPlatform\Exception\ItemNotFoundException;
16+
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
1717
use ApiPlatform\Metadata\IriConverterInterface;
1818
use Behat\Behat\Context\Context;
1919
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
@@ -618,7 +618,7 @@ public function iPatchPageDataWithThePropertyAndResource(string $property, strin
618618
{
619619
$iri = $this->restContext->resources[$resource];
620620
$this->restContext->iSendARequestToTheResourceWithBody(
621-
'PUT',
621+
'PATCH',
622622
'page_data',
623623
null,
624624
new PyStringNode([\sprintf('{ "%s": "%s" }', $property, $iri)], 0)

features/bootstrap/RestContext.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function castFromJson(string $value)
142142
*/
143143
public function iSendARequestToWithData($method, $url, TableNode $tableNode): void
144144
{
145+
$this->setContentTypeForMethod($method);
145146
$this->restContext->iSendARequestToWithBody($method, $url, new PyStringNode([json_encode($this->castTableNodeToArray($tableNode))], 0));
146147
}
147148

@@ -166,10 +167,16 @@ public function iSendARequestToTheResourceWithBody(string $method, string $resou
166167
throw new ExpectationException(\sprintf("The resource with name $resource has not been defined. (Components that exist are `%s`)", implode('`, `', array_keys($this->resources))), $this->minkContext->getSession()->getDriver());
167168
}
168169
$endpoint = $this->resources[$resource] . ($postfix ?: '');
170+
$this->setContentTypeForMethod($method);
169171

170172
return $this->restContext->iSendARequestToWithBody($method, $endpoint, $body ?? new PyStringNode([], 0));
171173
}
172174

175+
private function setContentTypeForMethod(string $method)
176+
{
177+
$this->restContext->iAddHeaderEqualTo('Content-Type', 'PATCH' === $method ? 'application/merge-patch+json' : 'application/ld+json');
178+
}
179+
173180
/**
174181
* @When /^I send a "([^"]*)" request to the resource "([^"]*)"(?: and the postfix "([^"]*)"|)? with data:$/i
175182
*/

features/bootstrap/UploadsContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Silverback\ApiComponentsBundle\Features\Bootstrap;
1515

16-
use ApiPlatform\Exception\ItemNotFoundException;
16+
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
1717
use ApiPlatform\Metadata\IriConverterInterface;
1818
use Behat\Behat\Context\Context;
1919
use Behat\Behat\Hook\Scope\BeforeScenarioScope;

features/main/current_version.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: In order to detect the current API Components Bundle Version
88
And I add "Content-Type" header equal to "<header>"
99
When I send a "GET" request to "/docs"
1010
Then the response status code should be 200
11-
And the JSON node "info.version" should match the regex '/^1\.0\.0 \((?:dev-[a-zA-Z0-9]+|1\.0\.0\+no\-version\-set)@(?:[a-zA-Z0-9]+)?\)$/'
11+
And the JSON node "info.version" should match the regex '/^1\.0\.0 \((?:dev-[a-zA-Z0-9\-]+|1\.0\.0\+no\-version\-set)@(?:[a-zA-Z0-9]+)?\)$/'
1212
Examples:
1313
| header |
1414
| application/json |

features/main/route.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Feature: Route resources
8383
@loginUser
8484
Scenario: I update a route path. A new redirect will be created.
8585
Given there is a PageData resource with the route path "/original"
86-
When I send a "PUT" request to "/_/routes//original" with data:
86+
When I send a "PATCH" request to "/_/routes//original" with data:
8787
| path |
8888
| /new |
8989
Then the response status code should be 200

features/publishable/publishable.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Feature: Access to unpublished/draft resources should be configurable
203203
Scenario: As a user with draft access, when I update a published resource, it should create and return a draft resource. Draft resource should not have the component position.
204204
Given there is a publishable resource set to publish at "1970-12-31T23:59:59+00:00"
205205
And there is a ComponentPosition with the resource "publishable_published"
206-
When I send a "PUT" request to the resource "publishable_published" with body:
206+
When I send a "PATCH" request to the resource "publishable_published" with body:
207207
"""
208208
{
209209
"reference": "updated"
@@ -247,7 +247,7 @@ Feature: Access to unpublished/draft resources should be configurable
247247
@loginAdmin
248248
Scenario Outline: As a user with draft access, when I update a published resource with a publication date in the past (or now), it should be ignored.
249249
Given there is a publishable resource set to publish at "1970-12-31T23:59:59+00:00"
250-
When I send a "PUT" request to the resource "publishable_published" with data:
250+
When I send a "PATCH" request to the resource "publishable_published" with data:
251251
| publishedAt |
252252
| <publishedAt> |
253253
Then the response status code should be 200
@@ -260,7 +260,7 @@ Feature: Access to unpublished/draft resources should be configurable
260260
@loginAdmin
261261
Scenario Outline: As a user with draft access, when I update a published/draft resource with a draft resource available, and set a publication date in the past (or now), it should update the draft resource, merge it with the public resource, and remove the draft resource.
262262
Given there is a published resource with a draft set to publish at "2999-12-31T23:59:59+00:00"
263-
When I send a "PUT" request to the resource "<component>" with data:
263+
When I send a "PATCH" request to the resource "<component>" with data:
264264
| publishedAt | reference |
265265
| <publishedAt> | updated |
266266
Then the response status code should be 200
@@ -278,7 +278,7 @@ Feature: Access to unpublished/draft resources should be configurable
278278
@loginAdmin
279279
Scenario: As a user with draft access, when I update a published resource with a draft resource available, and set a publication date in the future, it should update and return the draft resource.
280280
Given there is a published resource with a draft set to publish at "2999-12-31T23:59:59+00:00"
281-
When I send a "PUT" request to the resource "publishable_published" with body:
281+
When I send a "PATCH" request to the resource "publishable_published" with body:
282282
"""
283283
{
284284
"publishedAt": "2991-11-11T23:59:59+00:00"
@@ -291,7 +291,7 @@ Feature: Access to unpublished/draft resources should be configurable
291291
@loginUser
292292
Scenario: As a user with no draft access, when I update a published resource, it should update and return the published resource.
293293
Given there is a publishable resource set to publish at "1970-12-31T23:59:59+00:00"
294-
When I send a "PUT" request to the resource "publishable_published" with body:
294+
When I send a "PATCH" request to the resource "publishable_published" with body:
295295
"""
296296
{
297297
"reference": "updated"
@@ -304,7 +304,7 @@ Feature: Access to unpublished/draft resources should be configurable
304304
@loginUser
305305
Scenario: As a user with no draft access, I cannot update a draft resource.
306306
Given there is a publishable resource set to publish at "2999-12-31T23:59:59+00:00"
307-
When I send a "PUT" request to the resource "publishable_draft" with body:
307+
When I send a "PATCH" request to the resource "publishable_draft" with body:
308308
"""
309309
{
310310
"reference": "updated"
@@ -315,7 +315,7 @@ Feature: Access to unpublished/draft resources should be configurable
315315
@loginAdmin
316316
Scenario: I cannot modify the publishedResource property via the API
317317
Given there is a publishable resource set to publish at "2999-12-31T23:59:59+00:00"
318-
When I send a "PUT" request to the resource "publishable_draft" with body:
318+
When I send a "PATCH" request to the resource "publishable_draft" with body:
319319
"""
320320
{
321321
"reference": "updated",
@@ -410,7 +410,7 @@ Feature: Access to unpublished/draft resources should be configurable
410410
Scenario: When I publish a draft component where there is an existing published component, the newly published draft should inherit the old published component positions
411411
Given there is a published resource with a draft set to publish at "2999-12-31T23:59:59+00:00"
412412
And there is a ComponentPosition with the resource "publishable_published"
413-
When I send a "PUT" request to the resource "publishable_draft" with body:
413+
When I send a "PATCH" request to the resource "publishable_draft" with body:
414414
"""
415415
{
416416
"publishedAt": "1970-11-11T23:59:59+00:00"

features/publishable/publishable_soft_validation.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Feature: Soft validation on draft resources
3939
@loginAdmin
4040
Scenario Outline: When I update a draft resource, there should be a header to indicate whether validation is passing if I were to try and publish it
4141
Given there is a DummyPublishableWithValidation resource
42-
When I send a "PUT" request to the resource "publishable_draft" with data:
42+
When I send a "PATCH" request to the resource "publishable_draft" with data:
4343
| resourceData |
4444
| <data> |
4545
Then the response status code should be 200
@@ -53,7 +53,7 @@ Feature: Soft validation on draft resources
5353
@loginAdmin
5454
Scenario Outline: I update a draft resource with data that is OK for a draft, but not for published
5555
Given there is a DummyPublishableWithValidation resource
56-
When I send a "PUT" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
56+
When I send a "PATCH" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
5757
| publishedAt | resourceData |
5858
| <publishedAt> | <data> |
5959
Then the response status code should be <httpStatus>
@@ -66,7 +66,7 @@ Feature: Soft validation on draft resources
6666
@loginAdmin
6767
Scenario Outline: I update a draft resource with data that is valid to make it published when ready
6868
Given there is a DummyPublishableWithValidation resource
69-
When I send a "PUT" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
69+
When I send a "PATCH" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
7070
| publishedAt | resourceData |
7171
| <publishedAt> | <data> |
7272
Then the response status code should be <httpStatus>
@@ -80,7 +80,7 @@ Feature: Soft validation on draft resources
8080
@loginAdmin
8181
Scenario Outline: I update a draft resource and expect to see a hard fail with validation errors and no need to populate metadata as the output is the violations
8282
Given there is a DummyPublishableWithValidation resource
83-
When I send a "PUT" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
83+
When I send a "PATCH" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
8484
| publishedAt | resourceData |
8585
| <publishedAt> | <data> |
8686
Then the response status code should be <httpStatus>
@@ -100,7 +100,7 @@ Feature: Soft validation on draft resources
100100
@loginAdmin
101101
Scenario Outline: Updating a resource to published. The querystring should make no difference and the response is published so no header should exist
102102
Given there is a DummyPublishableWithValidation resource
103-
When I send a "PUT" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
103+
When I send a "PATCH" request to the resource "publishable_draft" and the postfix "?<postfix>" with data:
104104
| publishedAt | resourceData |
105105
| <publishedAt> | <data> |
106106
Then the response status code should be <httpStatus>
@@ -114,7 +114,7 @@ Feature: Soft validation on draft resources
114114
@loginAdmin
115115
Scenario: I update a published resource with the querystring "validate_published=false" and "published=true" should have no effect and published resource validation should still apply
116116
Given there is a DummyPublishableWithValidation resource set to publish at "1970-12-31T23:59:59+00:00"
117-
When I send a "PUT" request to the resource "publishable_published" and the postfix "?validate_published=false&published=true" with body:
117+
When I send a "PATCH" request to the resource "publishable_published" and the postfix "?validate_published=false&published=true" with body:
118118
"""
119119
{
120120
"description": ""

features/uploads/uploads.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Feature: API Resources which can have files uploaded
105105
@loginUser
106106
Scenario Outline: I can update a media resource
107107
Given there is a DummyUploadableWithImagineFilters
108-
When I send a "PUT" request to the resource "dummy_uploadable" with data:
108+
When I send a "PATCH" request to the resource "dummy_uploadable" with data:
109109
| file |
110110
| base64(<file>) |
111111
Then the response status code should be 200
@@ -154,7 +154,7 @@ Feature: API Resources which can have files uploaded
154154
@loginAdmin
155155
Scenario: I can set the file to null to delete it
156156
And there is a DummyUploadableWithImagineFilters
157-
When I send a "PUT" request to the resource "dummy_uploadable" with data:
157+
When I send a "PATCH" request to the resource "dummy_uploadable" with data:
158158
| file |
159159
| null |
160160
Then the response status code should be 200
@@ -183,7 +183,7 @@ Feature: API Resources which can have files uploaded
183183
Given there is a DummyUploadableAndPublishable
184184
And the resource "dummy_uploadable" has a file "<existing_file>"
185185
And there is a ComponentPosition with the resource "dummy_uploadable"
186-
When I send a "PUT" request to the resource "dummy_uploadable" with data:
186+
When I send a "PATCH" request to the resource "dummy_uploadable" with data:
187187
| file |
188188
| base64(<new_file>) |
189189
Then the response status code should be 200

0 commit comments

Comments
 (0)