Skip to content

Commit 681e4b5

Browse files
committed
Merge branch '2.2' into 2.3
2 parents 724c140 + d6b01d7 commit 681e4b5

File tree

6 files changed

+114
-7
lines changed

6 files changed

+114
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
* GraphQL: Add a `totalCount` field in GraphQL paginated collections
2020
* JSONAPI: Allow inclusion of related resources
2121

22+
## 2.2.9
23+
24+
* Fix `ExistsFilter` for inverse side of OneToOne association
25+
* Fix to not populate subresource inverse side
26+
* Improve the overall code quality (PHPStan analysis)
27+
2228
## 2.2.8
2329

2430
* Fix support for max depth when using subresources

features/bootstrap/FeatureContext.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Foo;
3535
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FooDummy;
3636
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FourthLevel;
37+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Greeting;
3738
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Node;
3839
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Person;
3940
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\PersonToPet;
@@ -786,6 +787,7 @@ public function thereIsAnAnswerToTheQuestion(string $a, string $q)
786787
$this->manager->persist($question);
787788

788789
$this->manager->flush();
790+
$this->manager->clear();
789791
}
790792

791793
/**
@@ -952,4 +954,23 @@ public function thereIsADummyObjectWithAFourthLevelRelation()
952954

953955
$this->manager->flush();
954956
}
957+
958+
/**
959+
* @Given there is a person named :name greeting with a :message message
960+
*/
961+
public function thereIsAPersonWithAGreeting(string $name, string $message)
962+
{
963+
$person = new Person();
964+
$person->name = $name;
965+
966+
$greeting = new Greeting();
967+
$greeting->message = $message;
968+
$greeting->sender = $person;
969+
970+
$this->manager->persist($person);
971+
$this->manager->persist($greeting);
972+
973+
$this->manager->flush();
974+
$this->manager->clear();
975+
}
955976
}

features/main/subresource.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,33 @@ Feature: Subresource support
316316
}
317317
"""
318318

319+
Scenario: The recipient of the person's greetings should be empty
320+
Given there is a person named "Alice" greeting with a "hello" message
321+
When I send a "GET" request to "/people/1/sent_greetings"
322+
And the response status code should be 200
323+
And the response should be in JSON
324+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
325+
And the JSON should be equal to:
326+
"""
327+
{
328+
"@context": "/contexts/Greeting",
329+
"@id": "/people/1/sent_greetings",
330+
"@type": "hydra:Collection",
331+
"hydra:member": [
332+
{
333+
"@id": "/greetings/1",
334+
"@type": "Greeting",
335+
"message": "hello",
336+
"sender": "/people/1",
337+
"recipient": null,
338+
"id": 1
339+
}
340+
],
341+
"hydra:totalItems": 1
342+
}
343+
"""
344+
345+
@dropSchema
319346
Scenario: Recursive resource
320347
When I send a "GET" request to "/dummy_products/2"
321348
And the response status code should be 200

src/Serializer/AbstractItemNormalizer.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Core\Serializer;
1515

1616
use ApiPlatform\Core\Api\IriConverterInterface;
17-
use ApiPlatform\Core\Api\OperationType;
1817
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
1918
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
2019
use ApiPlatform\Core\Exception\InvalidArgumentException;
@@ -483,12 +482,6 @@ protected function normalizeCollectionOfRelations(PropertyMetadata $propertyMeta
483482
*/
484483
protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, string $format = null, array $context)
485484
{
486-
// On a subresource, we know the value of the identifiers.
487-
// If attributeValue is null, meaning that it hasn't been returned by the DataProvider, get the item Iri
488-
if (null === $relatedObject && isset($context['operation_type'], $context['subresource_resources'][$resourceClass]) && OperationType::SUBRESOURCE === $context['operation_type']) {
489-
return $this->iriConverter->getItemIriFromResourceClass($resourceClass, $context['subresource_resources'][$resourceClass]);
490-
}
491-
492485
if (null === $relatedObject || $propertyMetadata->isReadableLink() || !empty($context['attributes'])) {
493486
if (null === $relatedObject) {
494487
unset($context['resource_class']);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\ORM\Mapping as ORM;
18+
19+
/**
20+
* @ApiResource
21+
* @ORM\Entity
22+
*/
23+
class Greeting
24+
{
25+
/**
26+
* @ORM\Id
27+
* @ORM\GeneratedValue
28+
* @ORM\Column(type="integer")
29+
*/
30+
private $id;
31+
32+
/**
33+
* @ORM\Column
34+
*/
35+
public $message = '';
36+
37+
/**
38+
* @ORM\ManyToOne(targetEntity="Person", inversedBy="sentGreetings")
39+
* @ORM\JoinColumn(name="sender_id")
40+
*/
41+
public $sender;
42+
43+
/**
44+
* @ORM\ManyToOne(targetEntity="Person")
45+
* @ORM\JoinColumn(name="recipient_id", nullable=true)
46+
*/
47+
public $recipient;
48+
49+
public function getId(): int
50+
{
51+
return $this->id;
52+
}
53+
}

tests/Fixtures/TestBundle/Entity/Person.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;
1515

1616
use ApiPlatform\Core\Annotation\ApiResource;
17+
use ApiPlatform\Core\Annotation\ApiSubresource;
1718
use Doctrine\Common\Collections\ArrayCollection;
1819
use Doctrine\ORM\Mapping as ORM;
1920
use Symfony\Component\Serializer\Annotation\Groups;
@@ -49,6 +50,12 @@ class Person
4950
*/
5051
public $pets;
5152

53+
/**
54+
* @ApiSubresource
55+
* @ORM\OneToMany(targetEntity="Greeting", mappedBy="sender")
56+
*/
57+
public $sentGreetings;
58+
5259
public function __construct()
5360
{
5461
$this->pets = new ArrayCollection();

0 commit comments

Comments
 (0)