Skip to content

Commit c0de241

Browse files
authored
Merge pull request #1949 from antograssiot/json-api-included-support
JSON-API - Add support to inclusion of related resources
2 parents bd2eadb + e2bf17c commit c0de241

File tree

14 files changed

+758
-55
lines changed

14 files changed

+758
-55
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,39 @@ public function thereAreDummyPropertyObjects(int $nb)
218218
$this->manager->flush();
219219
}
220220

221+
/**
222+
* @Given there are :nb dummy property objects with :nb2 groups
223+
*/
224+
public function thereAreDummyPropertyObjectsWithGroups(int $nb, int $nb2)
225+
{
226+
for ($i = 1; $i <= $nb; ++$i) {
227+
$dummyProperty = new DummyProperty();
228+
$dummyGroup = new DummyGroup();
229+
230+
foreach (['foo', 'bar', 'baz'] as $property) {
231+
$dummyProperty->$property = $dummyGroup->$property = ucfirst($property).' #'.$i;
232+
}
233+
234+
$dummyProperty->group = $dummyGroup;
235+
236+
$this->manager->persist($dummyGroup);
237+
for ($j = 1; $j <= $nb2; ++$j) {
238+
$dummyGroup = new DummyGroup();
239+
240+
foreach (['foo', 'bar', 'baz'] as $property) {
241+
$dummyGroup->$property = ucfirst($property).' #'.$i.$j;
242+
}
243+
244+
$dummyProperty->groups[] = $dummyGroup;
245+
$this->manager->persist($dummyGroup);
246+
}
247+
248+
$this->manager->persist($dummyProperty);
249+
}
250+
251+
$this->manager->flush();
252+
}
253+
221254
/**
222255
* @Given there are :nb embedded dummy objects
223256
*/

features/jsonapi/filtering.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ Feature: JSON API filter handling
2323
And the JSON should be valid according to the JSON API schema
2424
And the JSON node "data" should have 0 elements
2525

26+
Scenario: Apply property filter based on the 'fields'
27+
Given there are 2 dummy property objects
28+
When I send a "GET" request to "/dummy_properties?fields[DummyProperty]=id,foo,bar"
29+
Then the response status code should be 200
30+
And the response should be in JSON
31+
And the JSON should be valid according to the JSON API schema
32+
And the JSON node "data" should have 2 elements
33+
And the JSON node "data[0].attributes._id" should be equal to "1"
34+
And the JSON node "data[0].attributes.foo" should be equal to "Foo #1"
35+
And the JSON node "data[0].attributes.bar" should be equal to "Bar #1"
36+
And the JSON node "data[0].attributes.group" should not exist
37+
2638
Scenario: Apply filters based on the 'filter' query parameter with second level arguments
2739
When I send a "GET" request to "/dummies?filter[dummyDate][after]=2015-04-28"
2840
Then the response status code should be 200

0 commit comments

Comments
 (0)