Skip to content

Commit 2d972c0

Browse files
authored
Merge pull request #590 from api-platform/serializer_listener
Refactor the responder to ease usage of content negotiation
2 parents 1150b69 + 373af5b commit 2d972c0

File tree

80 files changed

+1013
-594
lines changed

Some content is hidden

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

80 files changed

+1013
-594
lines changed

features/content_negotiation.feature

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,51 @@ Feature: Content Negotiation support
1212
<name>XML!</name>
1313
</root>
1414
"""
15-
Then the header "Content-Type" should be equal to "application/xml"
15+
Then the response status code should be 201
16+
And the header "Content-Type" should be equal to "application/xml"
1617
And the response should be equal to
1718
"""
1819
<?xml version="1.0"?>
1920
<response><id>1</id><name>XML!</name><alias/><description/><dummyDate/><dummyPrice/><jsonData/><relatedDummy/><dummyBoolean/><dummy/><relatedDummies/><nameConverted/></response>
2021
"""
2122

23+
Scenario: Retrieve a collection in XML
24+
When I add "Accept" header equal to "text/xml"
25+
And I send a "GET" request to "/dummies"
26+
Then the response status code should be 200
27+
And the header "Content-Type" should be equal to "text/xml; charset=UTF-8"
28+
And the response should be equal to
29+
"""
30+
<?xml version="1.0"?>
31+
<response><item key="0"><id>1</id><name>XML!</name><alias/><description/><dummyDate/><dummyPrice/><jsonData/><relatedDummy/><dummyBoolean/><dummy/><relatedDummies/><nameConverted/></item></response>
32+
"""
33+
34+
Scenario: Retrieve a collection in JSON
35+
When I add "Accept" header equal to "application/json"
36+
And I send a "GET" request to "/dummies"
37+
Then the response status code should be 200
38+
And the header "Content-Type" should be equal to "application/json"
39+
And the response should be in JSON
40+
And the JSON should be equal to:
41+
"""
42+
[
43+
{
44+
"id": 1,
45+
"name": "XML!",
46+
"alias": null,
47+
"description": null,
48+
"dummyDate": null,
49+
"dummyPrice": null,
50+
"jsonData": [],
51+
"relatedDummy": null,
52+
"dummyBoolean": null,
53+
"dummy": null,
54+
"relatedDummies": [],
55+
"nameConverted": null
56+
}
57+
]
58+
"""
59+
2260
@dropSchema
2361
Scenario: Requesting an unknown format should return JSON-LD
2462
When I add "Accept" header equal to "text/plain"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

features/fos-user.feature renamed to features/fos_user.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Feature: Create-Retrieve-Update-Delete
1010
"""
1111
{
1212
"fullname": "Dummy User",
13+
"username": "dummy.user",
1314
"email": "[email protected]",
1415
"plainPassword": "azerty"
1516
}
File renamed without changes.
Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
Feature: Create-Retrieve-Update-Delete with custom attribute
1+
Feature: Create-Retrieve-Update-Delete with a Overridden Operation context
22
In order to use an hypermedia API
33
As a client software developer
44
I need to be able to retrieve, create, update and delete JSON-LD encoded resources.
55

66
@createSchema
77
Scenario: Create a resource
8-
When I send a "POST" request to "/custom_attribute_dummies" with body:
8+
When I send a "POST" request to "/overridden_operation_dummies" with body:
99
"""
1010
{
11-
"name": "My Custom Attribute Dummy",
11+
"name": "My Overridden Operation Dummy",
1212
"description" : "Gerard",
1313
"alias": "notWritable"
1414
}
@@ -19,52 +19,63 @@ Feature: Create-Retrieve-Update-Delete with custom attribute
1919
And the JSON should be equal to:
2020
"""
2121
{
22-
"@context": "/contexts/CustomAttributeDummy",
23-
"@id": "/custom_attribute_dummies/1",
24-
"@type": "CustomAttributeDummy",
25-
"name": "My Custom Attribute Dummy",
22+
"@context": "/contexts/OverriddenOperationDummy",
23+
"@id": "/overridden_operation_dummies/1",
24+
"@type": "OverriddenOperationDummy",
25+
"name": "My Overridden Operation Dummy",
2626
"alias": null,
2727
"description": "Gerard"
2828
}
2929
"""
3030

3131
Scenario: Get a resource
32-
When I send a "GET" request to "/custom_attribute_dummies/1"
32+
When I send a "GET" request to "/overridden_operation_dummies/1"
3333
Then the response status code should be 200
3434
And the response should be in JSON
3535
And the header "Content-Type" should be equal to "application/ld+json"
3636
And the JSON should be equal to:
3737
"""
3838
{
39-
"@context": "/contexts/CustomAttributeDummy",
40-
"@id": "/custom_attribute_dummies/1",
41-
"@type": "CustomAttributeDummy",
42-
"name": "My Custom Attribute Dummy",
39+
"@context": "/contexts/OverriddenOperationDummy",
40+
"@id": "/overridden_operation_dummies/1",
41+
"@type": "OverriddenOperationDummy",
42+
"name": "My Overridden Operation Dummy",
4343
"alias": null,
4444
"description": "Gerard"
4545
}
4646
"""
4747

48+
Scenario: Get a resource in XML
49+
When I add "Accept" header equal to "application/xml"
50+
And I send a "GET" request to "/overridden_operation_dummies/1"
51+
Then the response status code should be 200
52+
And the header "Content-Type" should be equal to "application/xml"
53+
And the response should be equal to
54+
"""
55+
<?xml version="1.0"?>
56+
<response><name>My Overridden Operation Dummy</name><alias/><description>Gerard</description></response>
57+
"""
58+
4859
Scenario: Get a not found exception
49-
When I send a "GET" request to "/custom_attribute_dummies/42"
60+
When I send a "GET" request to "/overridden_operation_dummies/42"
5061
Then the response status code should be 404
5162

5263
Scenario: Get a collection
53-
When I send a "GET" request to "/custom_attribute_dummies"
64+
When I send a "GET" request to "/overridden_operation_dummies"
5465
Then the response status code should be 200
5566
And the response should be in JSON
5667
And the header "Content-Type" should be equal to "application/ld+json"
5768
And the JSON should be equal to:
5869
"""
5970
{
60-
"@context": "/contexts/CustomAttributeDummy",
61-
"@id": "\/custom_attribute_dummies",
71+
"@context": "/contexts/OverriddenOperationDummy",
72+
"@id": "\/overridden_operation_dummies",
6273
"@type": "hydra:Collection",
6374
"hydra:member": [
6475
{
65-
"@id": "\/custom_attribute_dummies\/1",
66-
"@type": "CustomAttributeDummy",
67-
"name": "My Custom Attribute Dummy",
76+
"@id": "\/overridden_operation_dummies\/1",
77+
"@type": "OverriddenOperationDummy",
78+
"name": "My Overridden Operation Dummy",
6879
"alias": null,
6980
"description": "Gerard"
7081
}
@@ -74,10 +85,10 @@ Feature: Create-Retrieve-Update-Delete with custom attribute
7485
"""
7586

7687
Scenario: Update a resource
77-
When I send a "PUT" request to "/custom_attribute_dummies/1" with body:
88+
When I send a "PUT" request to "/overridden_operation_dummies/1" with body:
7889
"""
7990
{
80-
"@id": "/custom_attribute_dummies/1",
91+
"@id": "/overridden_operation_dummies/1",
8192
"name": "A nice dummy",
8293
"alias": "Dummy"
8394
}
@@ -88,32 +99,33 @@ Feature: Create-Retrieve-Update-Delete with custom attribute
8899
And the JSON should be equal to:
89100
"""
90101
{
91-
"@context": "/contexts/CustomAttributeDummy",
92-
"@id": "/custom_attribute_dummies/1",
93-
"@type": "CustomAttributeDummy",
102+
"@context": "/contexts/OverriddenOperationDummy",
103+
"@id": "/overridden_operation_dummies/1",
104+
"@type": "OverriddenOperationDummy",
94105
"alias": "Dummy",
95106
"description": "Gerard"
96107
}
97108
"""
98109

99110
Scenario: Get the final resource
100-
When I send a "GET" request to "/custom_attribute_dummies/1"
111+
When I send a "GET" request to "/overridden_operation_dummies/1"
101112
Then the response status code should be 200
102113
And the response should be in JSON
103114
And the header "Content-Type" should be equal to "application/ld+json"
104115
And the JSON should be equal to:
105116
"""
106117
{
107-
"@context": "/contexts/CustomAttributeDummy",
108-
"@id": "/custom_attribute_dummies/1",
109-
"@type": "CustomAttributeDummy",
110-
"name": "My Custom Attribute Dummy",
118+
"@context": "/contexts/OverriddenOperationDummy",
119+
"@id": "/overridden_operation_dummies/1",
120+
"@type": "OverriddenOperationDummy",
121+
"name": "My Overridden Operation Dummy",
111122
"alias": "Dummy",
112123
"description": "Gerard"
113124
}
114125
"""
126+
115127
@dropSchema
116128
Scenario: Delete a resource
117-
When I send a "DELETE" request to "/custom_attribute_dummies/1"
129+
When I send a "DELETE" request to "/overridden_operation_dummies/1"
118130
Then the response status code should be 204
119131
And the response should be empty

0 commit comments

Comments
 (0)