Skip to content

Commit b7afbf8

Browse files
authored
Merge pull request #2679 from teohhanhui/fix/normalize-non-resource
Normalize non-resource objects in a standalone normalizer
2 parents 5272e3d + 521fa98 commit b7afbf8

Some content is hidden

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

46 files changed

+1306
-736
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ jobs:
215215
mkdir -p build/logs/tmp build/cov
216216
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature' -not -path 'features/elasticsearch/*' -not -path 'features/mongodb/*' | circleci tests split --split-by=timings); do
217217
_f=${f//\//_}
218-
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --format=progress --out=std --format=junit --out=build/logs/tmp/"${_f}" "$f"
218+
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --format=progress --out=std --format=junit --out=build/logs/tmp/"${_f}" --no-interaction "$f"
219219
done
220220
- run:
221221
name: Merge Behat test reports

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ script:
6868
fi
6969
- tests/Fixtures/app/console cache:clear
7070
- if [[ $APP_ENV = 'postgres' ]]; then
71-
vendor/bin/behat --suite=postgres --format=progress;
71+
vendor/bin/behat --suite=postgres --format=progress --no-interaction;
7272
elif [[ $APP_ENV = 'mongodb' ]]; then
73-
vendor/bin/behat --suite=mongodb --format=progress;
73+
vendor/bin/behat --suite=mongodb --format=progress --no-interaction;
7474
elif [[ $APP_ENV = 'elasticsearch' ]]; then
75-
vendor/bin/behat --suite=elasticsearch --format=progress;
75+
vendor/bin/behat --suite=elasticsearch --format=progress --no-interaction;
7676
else
77-
vendor/bin/behat --suite=default --format=progress;
77+
vendor/bin/behat --suite=default --format=progress --no-interaction;
7878
fi
7979
- tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
8080
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ services:
3333

3434
test_script:
3535
- cd %APPVEYOR_BUILD_FOLDER%
36-
- php vendor\behat\behat\bin\behat --format=progress --suite=default
36+
- php vendor\behat\behat\bin\behat --format=progress --suite=default --no-interaction
3737
- rmdir tests\Fixtures\app\var\cache /s /q
3838
- php vendor\phpunit\phpunit\phpunit

features/bootstrap/JsonContext.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,6 @@ public function __construct(HttpCallResultPool $httpCallResultPool)
2424
parent::__construct($httpCallResultPool);
2525
}
2626

27-
private function sortArrays($obj)
28-
{
29-
$isObject = is_object($obj);
30-
31-
foreach ($obj as $key => $value) {
32-
if (null === $value || is_scalar($value)) {
33-
continue;
34-
}
35-
36-
if (is_array($value)) {
37-
sort($value);
38-
}
39-
40-
$value = $this->sortArrays($value);
41-
42-
$isObject ? $obj->{$key} = $value : $obj[$key] = $value;
43-
}
44-
45-
return $obj;
46-
}
47-
4827
/**
4928
* @Then /^the JSON should be deep equal to:$/
5029
*/
@@ -75,4 +54,25 @@ public function theJsonIsASupersetOf(PyStringNode $content)
7554
$actual = json_decode($this->httpCallResultPool->getResult()->getValue(), true);
7655
Assert::assertArraySubset(json_decode($content->getRaw(), true), $actual);
7756
}
57+
58+
private function sortArrays($obj)
59+
{
60+
$isObject = is_object($obj);
61+
62+
foreach ($obj as $key => $value) {
63+
if (null === $value || is_scalar($value)) {
64+
continue;
65+
}
66+
67+
if (is_array($value)) {
68+
sort($value);
69+
}
70+
71+
$value = $this->sortArrays($value);
72+
73+
$isObject ? $obj->{$key} = $value : $obj[$key] = $value;
74+
}
75+
76+
return $obj;
77+
}
7878
}

features/doctrine/search_filter.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Feature: Search filter on collections
5050
},
5151
"hydra:search": {
5252
"@type": "hydra:IriTemplate",
53-
"hydra:template": "\/dummy_cars{?availableAt[before],availableAt[strictly_before],availableAt[after],availableAt[strictly_after],canSell,foobar[],foobargroups[],foobargroups_override[],colors.prop,name}",
53+
"hydra:template": "/dummy_cars{?availableAt[before],availableAt[strictly_before],availableAt[after],availableAt[strictly_after],canSell,foobar[],foobargroups[],foobargroups_override[],colors.prop,name}",
5454
"hydra:variableRepresentation": "BasicRepresentation",
5555
"hydra:mapping": [
5656
{

features/graphql/input_output.feature

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
Feature: GraphQL DTO input and output
2+
In order to use a hypermedia API
3+
As a client software developer
4+
I need to be able to use DTOs on my resources as Input or Output objects.
5+
6+
@createSchema
7+
Scenario: Retrieve an Output with GraphQl
8+
When I add "Content-Type" header equal to "application/ld+json"
9+
And I send a "POST" request to "/dummy_dto_input_outputs" with body:
10+
"""
11+
{
12+
"foo": "test",
13+
"bar": 1
14+
}
15+
"""
16+
Then the response status code should be 201
17+
And the JSON should be equal to:
18+
"""
19+
{
20+
"@context": {
21+
"@vocab": "http://example.com/docs.jsonld#",
22+
"hydra": "http://www.w3.org/ns/hydra/core#",
23+
"id": "OutputDto/id",
24+
"baz": "OutputDto/baz",
25+
"bat": "OutputDto/bat"
26+
},
27+
"@type": "DummyDtoInputOutput",
28+
"@id": "/dummy_dto_input_outputs/1",
29+
"id": 1,
30+
"baz": 1,
31+
"bat": "test"
32+
}
33+
"""
34+
When I send the following GraphQL request:
35+
"""
36+
{
37+
dummyDtoInputOutput(id: "/dummy_dto_input_outputs/1") {
38+
_id, id, baz
39+
}
40+
}
41+
"""
42+
Then the response status code should be 200
43+
And the response should be in JSON
44+
And the header "Content-Type" should be equal to "application/json"
45+
And the JSON should be equal to:
46+
"""
47+
{
48+
"data": {
49+
"dummyDtoInputOutput": {
50+
"_id": 1,
51+
"id": "/dummy_dto_input_outputs/1",
52+
"baz": 1
53+
}
54+
}
55+
}
56+
"""
57+
58+
Scenario: Create an item using custom inputClass & disabled outputClass
59+
Given there are 2 dummyDtoNoOutput objects
60+
When I send the following GraphQL request:
61+
"""
62+
mutation {
63+
createDummyDtoNoOutput(input: {foo: "A new one", bar: 3, clientMutationId: "myId"}) {
64+
dummyDtoNoOutput {
65+
id
66+
}
67+
clientMutationId
68+
}
69+
}
70+
"""
71+
Then the response status code should be 200
72+
And the response should be in JSON
73+
And the header "Content-Type" should be equal to "application/json"
74+
And the JSON should be equal to:
75+
"""
76+
{
77+
"errors": [
78+
{
79+
"message": "Cannot query field \"id\" on type \"DummyDtoNoOutput\".",
80+
"extensions": {
81+
"category": "graphql"
82+
},
83+
"locations": [
84+
{
85+
"line": 4,
86+
"column": 7
87+
}
88+
]
89+
}
90+
]
91+
}
92+
"""
93+
94+
Scenario: Cannot create an item with input fields using disabled inputClass
95+
When I send the following GraphQL request:
96+
"""
97+
mutation {
98+
createDummyDtoNoInput(input: {lorem: "A new one", ipsum: 3, clientMutationId: "myId"}) {
99+
clientMutationId
100+
}
101+
}
102+
"""
103+
Then the response status code should be 200
104+
And the response should be in JSON
105+
And the header "Content-Type" should be equal to "application/json"
106+
And the JSON should be equal to:
107+
"""
108+
{
109+
"errors": [
110+
{
111+
"message": "Field \"lorem\" is not defined by type createDummyDtoNoInputInput.",
112+
"extensions": {
113+
"category": "graphql"
114+
},
115+
"locations": [
116+
{
117+
"line": 2,
118+
"column": 33
119+
}
120+
]
121+
},
122+
{
123+
"message": "Field \"ipsum\" is not defined by type createDummyDtoNoInputInput.",
124+
"extensions": {
125+
"category": "graphql"
126+
},
127+
"locations": [
128+
{
129+
"line": 2,
130+
"column": 53
131+
}
132+
]
133+
}
134+
]
135+
}
136+
"""
137+
138+
Scenario: Create an item with empty input fields using disabled inputClass (no persist done)
139+
When I send the following GraphQL request:
140+
"""
141+
mutation {
142+
createDummyDtoNoInput(input: {clientMutationId: "myId"}) {
143+
dummyDtoNoInput {
144+
id
145+
}
146+
clientMutationId
147+
}
148+
}
149+
"""
150+
Then the response status code should be 200
151+
And the response should be in JSON
152+
And the header "Content-Type" should be equal to "application/json"
153+
And the JSON should be equal to:
154+
"""
155+
{
156+
"data": {
157+
"createDummyDtoNoInput": {
158+
"dummyDtoNoInput": null,
159+
"clientMutationId": "myId"
160+
}
161+
}
162+
}
163+
"""
164+
165+
@!mongodb
166+
Scenario: Use messenger with graphql and an input where the handler gives a synchronous result
167+
When I send the following GraphQL request:
168+
"""
169+
mutation {
170+
createMessengerWithInput(input: {var: "test"}) {
171+
messengerWithInput { id, name }
172+
}
173+
}
174+
"""
175+
Then the response status code should be 200
176+
And the response should be in JSON
177+
And the header "Content-Type" should be equal to "application/json"
178+
And the JSON should be equal to:
179+
"""
180+
{
181+
"data": {
182+
"createMessengerWithInput": {
183+
"messengerWithInput": {
184+
"id": "/messenger_with_inputs/1",
185+
"name": "test"
186+
}
187+
}
188+
}
189+
}
190+
"""

features/graphql/mutation.feature

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -328,110 +328,3 @@ Feature: GraphQL mutation support
328328
And the response should be in JSON
329329
And the header "Content-Type" should be equal to "application/json"
330330
And the JSON node "errors[0].message" should be equal to "name: This value should not be blank."
331-
332-
Scenario: Create an item using custom inputClass & disabled outputClass
333-
Given there are 2 dummyDtoNoOutput objects
334-
When I send the following GraphQL request:
335-
"""
336-
mutation {
337-
createDummyDtoNoOutput(input: {foo: "A new one", bar: 3, clientMutationId: "myId"}) {
338-
dummyDtoNoOutput {
339-
id
340-
}
341-
clientMutationId
342-
}
343-
}
344-
"""
345-
Then the response status code should be 200
346-
And the response should be in JSON
347-
And the header "Content-Type" should be equal to "application/json"
348-
And the JSON should be equal to:
349-
"""
350-
{
351-
"errors": [
352-
{
353-
"message": "Cannot query field \"id\" on type \"DummyDtoNoOutput\".",
354-
"extensions": {
355-
"category": "graphql"
356-
},
357-
"locations": [
358-
{
359-
"line": 4,
360-
"column": 7
361-
}
362-
]
363-
}
364-
]
365-
}
366-
"""
367-
368-
Scenario: Cannot create an item with input fields using disabled inputClass
369-
When I send the following GraphQL request:
370-
"""
371-
mutation {
372-
createDummyDtoNoInput(input: {lorem: "A new one", ipsum: 3, clientMutationId: "myId"}) {
373-
clientMutationId
374-
}
375-
}
376-
"""
377-
Then the response status code should be 200
378-
And the response should be in JSON
379-
And the header "Content-Type" should be equal to "application/json"
380-
And the JSON should be equal to:
381-
"""
382-
{
383-
"errors": [
384-
{
385-
"message": "Field \"lorem\" is not defined by type createDummyDtoNoInputInput.",
386-
"extensions": {
387-
"category": "graphql"
388-
},
389-
"locations": [
390-
{
391-
"line": 2,
392-
"column": 33
393-
}
394-
]
395-
},
396-
{
397-
"message": "Field \"ipsum\" is not defined by type createDummyDtoNoInputInput.",
398-
"extensions": {
399-
"category": "graphql"
400-
},
401-
"locations": [
402-
{
403-
"line": 2,
404-
"column": 53
405-
}
406-
]
407-
}
408-
]
409-
}
410-
"""
411-
412-
Scenario: Create an item with empty input fields using disabled inputClass (no persist done)
413-
When I send the following GraphQL request:
414-
"""
415-
mutation {
416-
createDummyDtoNoInput(input: {clientMutationId: "myId"}) {
417-
dummyDtoNoInput {
418-
id
419-
}
420-
clientMutationId
421-
}
422-
}
423-
"""
424-
Then the response status code should be 200
425-
And the response should be in JSON
426-
And the header "Content-Type" should be equal to "application/json"
427-
And the JSON should be equal to:
428-
"""
429-
{
430-
"data": {
431-
"createDummyDtoNoInput": {
432-
"dummyDtoNoInput": null,
433-
"clientMutationId": "myId"
434-
}
435-
}
436-
}
437-
"""

0 commit comments

Comments
 (0)