Skip to content

Commit 81a50f5

Browse files
authored
Merge pull request #2284 from antograssiot/collection-purge
Add tests on doctrine collection purge
2 parents c569c0f + d2cfbbc commit 81a50f5

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

features/http_cache/tags.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,40 @@ Feature: Cache invalidation through HTTP Cache tags
103103
"""
104104
Then the response status code should be 200
105105
And "/relation1s,/relation1s/1,/relation2s/2,/relation2s/1" IRIs should be purged
106+
107+
Scenario: Create a Relation3 with many to many
108+
When I add "Content-Type" header equal to "application/ld+json"
109+
And I send a "POST" request to "/relation3s" with body:
110+
"""
111+
{
112+
"relation2s": ["/relation2s/1", "/relation2s/2"]
113+
}
114+
"""
115+
Then the response status code should be 201
116+
And "/relation3s,/relation2s/1,/relation2s/2" IRIs should be purged
117+
118+
Scenario: Get a Relation3
119+
When I add "Content-Type" header equal to "application/ld+json"
120+
And I send a "GET" request to "/relation3s"
121+
Then the response status code should be 200
122+
And the header "Cache-Tags" should be equal to "/relation3s/1,/relation2s/1,/relation2s/2,/relation3s"
123+
124+
Scenario: Update a collection member only
125+
When I add "Content-Type" header equal to "application/ld+json"
126+
And I send a "PUT" request to "/relation3s/1" with body:
127+
"""
128+
{
129+
"relation2s": ["/relation2s/2"]
130+
}
131+
"""
132+
Then the response status code should be 200
133+
And the header "Cache-Tags" should not exist
134+
And "/relation3s,/relation3s/1,/relation2s/2,/relation2s,/relation2s/1" IRIs should be purged
135+
136+
Scenario: Delete the collection owner
137+
When I add "Content-Type" header equal to "application/ld+json"
138+
And I send a "DELETE" request to "/relation3s/1"
139+
Then the response status code should be 204
140+
And the header "Cache-Tags" should not exist
141+
And "/relation3s,/relation3s/1,/relation2s/2" IRIs should be purged
142+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Core\Annotation\ApiResource;
17+
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\ORM\Mapping as ORM;
19+
20+
/**
21+
* @ApiResource
22+
* @ORM\Entity
23+
*/
24+
class Relation3
25+
{
26+
/**
27+
* @ORM\Column(type="integer")
28+
* @ORM\Id
29+
* @ORM\GeneratedValue
30+
*/
31+
public $id;
32+
33+
/**
34+
* @ORM\ManyToMany(targetEntity="Relation2", orphanRemoval=true)
35+
*/
36+
private $relation2s;
37+
38+
public function __construct()
39+
{
40+
$this->relation2s = new ArrayCollection();
41+
}
42+
43+
public function getRelation2s()
44+
{
45+
return $this->relation2s;
46+
}
47+
48+
public function addRelation2(Relation2 $relation)
49+
{
50+
$this->relation2s->add($relation);
51+
52+
return $this;
53+
}
54+
55+
public function removeRelation2(Relation2 $relation)
56+
{
57+
$this->relation2s->removeElement($relation);
58+
59+
return $this;
60+
}
61+
}

0 commit comments

Comments
 (0)