Skip to content

Commit f06a3a7

Browse files
author
abluchet
committed
Fix filter Eager Loading #944
1 parent d65c84b commit f06a3a7

File tree

15 files changed

+522
-27
lines changed

15 files changed

+522
-27
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeLabel;
1414
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation;
1515
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
16+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar;
17+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCarColor;
18+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyFriend;
1619
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
1720
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
21+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedToDummyFriend;
1822
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelationEmbedder;
1923
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UuidIdentifierDummy;
2024
use Behat\Behat\Context\Context;
@@ -135,18 +139,21 @@ public function thereIsDummyObjectsWithRelatedDummy($nb)
135139
}
136140

137141
/**
138-
* @Given there is :nb dummy objects with relatedDummies
142+
* @Given there is :nb dummy objects having each :nbrelated relatedDummies
139143
*/
140-
public function thereIsDummyObjectsWithRelatedDummies($nb)
144+
public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
141145
{
142146
for ($i = 1; $i <= $nb; ++$i) {
143-
$relatedDummy = new RelatedDummy();
144-
$relatedDummy->setName('RelatedDummy #'.$i);
145-
146147
$dummy = new Dummy();
147148
$dummy->setName('Dummy #'.$i);
148149
$dummy->setAlias('Alias #'.($nb - $i));
149-
$dummy->addRelatedDummy($relatedDummy);
150+
151+
for ($j = 1; $j <= $nbrelated; ++$j) {
152+
$relatedDummy = new RelatedDummy();
153+
$relatedDummy->setName('RelatedDummy'.$j.$i);
154+
$this->manager->persist($relatedDummy);
155+
$dummy->addRelatedDummy($relatedDummy);
156+
}
150157

151158
$this->manager->persist($relatedDummy);
152159
$this->manager->persist($dummy);
@@ -311,4 +318,60 @@ public function thereIsAFileConfigDummyObject()
311318
$this->manager->persist($fileConfigDummy);
312319
$this->manager->flush();
313320
}
321+
322+
/**
323+
* @Given there is a DummyCar entity with related colors
324+
*/
325+
public function thereIsAFooEntityWithRelatedBars()
326+
{
327+
$foo = new DummyCar();
328+
$this->manager->persist($foo);
329+
330+
$bar1 = new DummyCarColor();
331+
$bar1->setProp('red');
332+
$bar1->setCar($foo);
333+
$this->manager->persist($bar1);
334+
335+
$bar2 = new DummyCarColor();
336+
$bar2->setProp('blue');
337+
$bar2->setCar($foo);
338+
$this->manager->persist($bar2);
339+
340+
$foo->setColors([$bar1, $bar2]);
341+
$this->manager->persist($foo);
342+
343+
$this->manager->flush();
344+
}
345+
346+
/**
347+
* @Given there is a RelatedDummy with :nb friends
348+
*/
349+
public function thereIsARelatedDummyWithFriends($nb)
350+
{
351+
$relatedDummy = new RelatedDummy();
352+
$relatedDummy->setName('RelatedDummy with friends');
353+
$this->manager->persist($relatedDummy);
354+
355+
for ($i = 1; $i <= $nb; ++$i) {
356+
$friend = new DummyFriend();
357+
$friend->setName('Friend-'.$i);
358+
359+
$this->manager->persist($friend);
360+
361+
$relation = new RelatedToDummyFriend();
362+
$relation->setName('Relation-'.$i);
363+
$relation->setDummyFriend($friend);
364+
$relation->setRelatedDummy($relatedDummy);
365+
366+
$relatedDummy->addRelatedToDummyFriend($relation);
367+
368+
$this->manager->persist($relation);
369+
}
370+
371+
$relatedDummy2 = new RelatedDummy();
372+
$relatedDummy2->setName('RelatedDummy without friends');
373+
$this->manager->persist($relatedDummy2);
374+
375+
$this->manager->flush();
376+
}
314377
}

features/doctrine/date_filter.feature

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,18 @@ Feature: Date filter on collections
389389
And the JSON should be equal to:
390390
"""
391391
{
392-
"@context": "\/contexts\/Dummy",
393-
"@id": "\/dummies",
392+
"@context": "/contexts/Dummy",
393+
"@id": "/dummies",
394394
"@type": "hydra:Collection",
395395
"hydra:member": [],
396396
"hydra:totalItems": 0,
397397
"hydra:view": {
398-
"@id": "\/dummies?relatedDummy.dummyDate%5Bafter%5D=2015-04-28",
398+
"@id": "/dummies?relatedDummy.dummyDate%5Bafter%5D=2015-04-28",
399399
"@type": "hydra:PartialCollectionView"
400400
},
401401
"hydra:search": {
402402
"@type": "hydra:IriTemplate",
403-
"hydra:template": "\/dummies{?id,id[],name,alias,description,relatedDummy.name,relatedDummy.name[],relatedDummies,relatedDummies[],dummy,order[id],order[name],order[relatedDummy.symfony],dummyDate[before],dummyDate[after],relatedDummy.dummyDate[before],relatedDummy.dummyDate[after],dummyFloat[between],dummyFloat[gt],dummyFloat[gte],dummyFloat[lt],dummyFloat[lte],dummyPrice[between],dummyPrice[gt],dummyPrice[gte],dummyPrice[lt],dummyPrice[lte],dummyBoolean,dummyFloat,dummyPrice}",
403+
"hydra:template": "/dummies{?id,id[],name,alias,description,relatedDummy.name,relatedDummy.name[],relatedDummies,relatedDummies[],dummy,relatedDummies.name,order[id],order[name],order[relatedDummy.symfony],dummyDate[before],dummyDate[after],relatedDummy.dummyDate[before],relatedDummy.dummyDate[after],dummyFloat[between],dummyFloat[gt],dummyFloat[gte],dummyFloat[lt],dummyFloat[lte],dummyPrice[between],dummyPrice[gt],dummyPrice[gte],dummyPrice[lt],dummyPrice[lte],dummyBoolean,dummyFloat,dummyPrice}",
404404
"hydra:variableRepresentation": "BasicRepresentation",
405405
"hydra:mapping": [
406406
{
@@ -463,6 +463,12 @@ Feature: Date filter on collections
463463
"property": "dummy",
464464
"required": false
465465
},
466+
{
467+
"@type": "IriTemplateMapping",
468+
"variable": "relatedDummies.name",
469+
"property": "relatedDummies.name",
470+
"required": false
471+
},
466472
{
467473
"@type": "IriTemplateMapping",
468474
"variable": "order[id]",

features/doctrine/search_filter.feature

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,66 @@ Feature: Search filter on collections
44
I need to search for collections properties
55

66
@createSchema
7+
@dropSchema
8+
Scenario: Test ManyToMany with filter on join table
9+
Given there is a RelatedDummy with 4 friends
10+
When I add "Accept" header equal to "application/hal+json"
11+
And I send a "GET" request to "/related_dummies?relatedToDummyFriend.dummyFriend=/dummy_friends/4"
12+
Then the response status code should be 200
13+
And the JSON node "_embedded.item" should have 1 element
14+
And the JSON node "_embedded.item[0]._links.relatedToDummyFriend" should have 4 elements
15+
And the JSON node "_embedded.item[0]._embedded.relatedToDummyFriend" should have 4 elements
16+
17+
@createSchema
18+
Scenario: Test #944
19+
Given there is a DummyCar entity with related colors
20+
When I send a "GET" request to "/dummy_cars?colors.prop=red"
21+
Then the response status code should be 200
22+
And the JSON should be equal to:
23+
"""
24+
{
25+
"@context": "/contexts/DummyCar",
26+
"@id": "/dummy_cars",
27+
"@type": "hydra:Collection",
28+
"hydra:member": [
29+
{
30+
"@id": "/dummy_cars/1",
31+
"@type": "DummyCar",
32+
"colors": [
33+
{
34+
"@id": "/dummy_car_colors/1",
35+
"@type": "DummyCarColor",
36+
"prop": "red"
37+
},
38+
{
39+
"@id": "/dummy_car_colors/2",
40+
"@type": "DummyCarColor",
41+
"prop": "blue"
42+
}
43+
]
44+
}
45+
],
46+
"hydra:totalItems": 1,
47+
"hydra:view": {
48+
"@id": "/dummy_cars?colors.prop=red",
49+
"@type": "hydra:PartialCollectionView"
50+
},
51+
"hydra:search": {
52+
"@type": "hydra:IriTemplate",
53+
"hydra:template": "/dummy_cars{?colors.prop}",
54+
"hydra:variableRepresentation": "BasicRepresentation",
55+
"hydra:mapping": [
56+
{
57+
"@type": "IriTemplateMapping",
58+
"variable": "colors.prop",
59+
"property": "colors.prop",
60+
"required": false
61+
}
62+
]
63+
}
64+
}
65+
"""
66+
767
Scenario: Search collection by name (partial)
868
Given there is "30" dummy objects
969
When I send a "GET" request to "/dummies?name=my"
@@ -42,7 +102,6 @@ Feature: Search filter on collections
42102
"""
43103

44104
Scenario: Search collection by name (partial case insensitive)
45-
Given there is "30" dummy objects
46105
When I send a "GET" request to "/dummies?dummy=somedummytest1"
47106
Then the response status code should be 200
48107
And the response should be in JSON
@@ -167,3 +226,17 @@ Feature: Search filter on collections
167226
}
168227
}
169228
"""
229+
230+
@createSchema
231+
@dropSchema
232+
Scenario: Search related collection by name
233+
Given there is 3 dummy objects having each 3 relatedDummies
234+
When I add "Accept" header equal to "application/hal+json"
235+
And I send a "GET" request to "/dummies?relatedDummies.name=RelatedDummy1"
236+
Then the response status code should be 200
237+
And the response should be in JSON
238+
And the JSON node "_embedded.item" should have 3 elements
239+
And the JSON node "_embedded.item[0]._links.relatedDummies" should have 3 elements
240+
And the JSON node "_embedded.item[1]._links.relatedDummies" should have 3 elements
241+
And the JSON node "_embedded.item[2]._links.relatedDummies" should have 3 elements
242+

features/main/crud.feature

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Feature: Create-Retrieve-Update-Delete
123123
"hydra:totalItems": 1,
124124
"hydra:search": {
125125
"@type": "hydra:IriTemplate",
126-
"hydra:template": "/dummies{?id,id[],name,alias,description,relatedDummy.name,relatedDummy.name[],relatedDummies,relatedDummies[],dummy,order[id],order[name],order[relatedDummy.symfony],dummyDate[before],dummyDate[after],relatedDummy.dummyDate[before],relatedDummy.dummyDate[after],dummyFloat[between],dummyFloat[gt],dummyFloat[gte],dummyFloat[lt],dummyFloat[lte],dummyPrice[between],dummyPrice[gt],dummyPrice[gte],dummyPrice[lt],dummyPrice[lte],dummyBoolean,dummyFloat,dummyPrice}",
126+
"hydra:template": "/dummies{?id,id[],name,alias,description,relatedDummy.name,relatedDummy.name[],relatedDummies,relatedDummies[],dummy,relatedDummies.name,order[id],order[name],order[relatedDummy.symfony],dummyDate[before],dummyDate[after],relatedDummy.dummyDate[before],relatedDummy.dummyDate[after],dummyFloat[between],dummyFloat[gt],dummyFloat[gte],dummyFloat[lt],dummyFloat[lte],dummyPrice[between],dummyPrice[gt],dummyPrice[gte],dummyPrice[lt],dummyPrice[lte],dummyBoolean,dummyFloat,dummyPrice}",
127127
"hydra:variableRepresentation": "BasicRepresentation",
128128
"hydra:mapping": [
129129
{
@@ -186,6 +186,12 @@ Feature: Create-Retrieve-Update-Delete
186186
"property": "dummy",
187187
"required": false
188188
},
189+
{
190+
"@type": "IriTemplateMapping",
191+
"variable": "relatedDummies.name",
192+
"property": "relatedDummies.name",
193+
"required": false
194+
},
189195
{
190196
"@type": "IriTemplateMapping",
191197
"variable": "order[id]",

features/main/relation.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ Feature: Relations support
6060
"@context": "/contexts/RelatedDummy",
6161
"@id": "/related_dummies/1",
6262
"@type": "https://schema.org/Product",
63+
"id": 1,
6364
"name": null,
65+
"symfony": "symfony",
6466
"dummyDate": null,
6567
"thirdLevel": "/third_levels/1",
66-
"relatedToDummyFriend": null,
68+
"relatedToDummyFriend": [],
6769
"dummyBoolean": null,
68-
"id": 1,
69-
"symfony": "symfony",
7070
"age": null
7171
}
7272
"""

0 commit comments

Comments
 (0)