Skip to content

Commit 717b909

Browse files
authored
Merge pull request #2797 from teohhanhui/fix/resource-class-resolver-inheritance
Fix ResourceClassResolver handling of inheritance
2 parents a6c5f98 + 79c3a65 commit 717b909

File tree

59 files changed

+2298
-1203
lines changed

Some content is hidden

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

59 files changed

+2298
-1203
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyOffer as DummyOfferDocument;
3232
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProduct as DummyProductDocument;
3333
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProperty as DummyPropertyDocument;
34+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyTableInheritanceNotApiResourceChild as DummyTableInheritanceNotApiResourceChildDocument;
3435
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddableDummy as EmbeddableDummyDocument;
3536
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddedDummy as EmbeddedDummyDocument;
3637
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FileConfigDummy as FileConfigDummyDocument;
@@ -74,6 +75,7 @@
7475
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyOffer;
7576
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProduct;
7677
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProperty;
78+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
7779
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
7880
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
7981
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
@@ -165,6 +167,17 @@ public function thereAreDummyObjects(int $nb)
165167
$this->manager->flush();
166168
}
167169

170+
/**
171+
* @When some dummy table inheritance data but not api resource child are created
172+
*/
173+
public function someDummyTableInheritanceDataButNotApiResourceChildAreCreated()
174+
{
175+
$dummy = $this->buildDummyTableInheritanceNotApiResourceChild();
176+
$dummy->setName('Foobarbaz inheritance');
177+
$this->manager->persist($dummy);
178+
$this->manager->flush();
179+
}
180+
168181
/**
169182
* @Given there are :nb foo objects with fake names
170183
*/
@@ -1272,6 +1285,14 @@ private function buildDummy()
12721285
return $this->isOrm() ? new Dummy() : new DummyDocument();
12731286
}
12741287

1288+
/**
1289+
* @return DummyTableInheritanceNotApiResourceChild|DummyTableInheritanceNotApiResourceChildDocument
1290+
*/
1291+
private function buildDummyTableInheritanceNotApiResourceChild()
1292+
{
1293+
return $this->isOrm() ? new DummyTableInheritanceNotApiResourceChild() : new DummyTableInheritanceNotApiResourceChildDocument();
1294+
}
1295+
12751296
/**
12761297
* @return DummyAggregateOffer|DummyAggregateOfferDocument
12771298
*/
@@ -1540,4 +1561,44 @@ public function testEagerLoadingNotDuplicateRelation()
15401561
$this->manager->flush();
15411562
$this->manager->clear();
15421563
}
1564+
1565+
/**
1566+
* @Given there are :nb sites with internal owner
1567+
*/
1568+
public function thereAreSitesWithInternalOwner(int $nb)
1569+
{
1570+
for ($i = 1; $i <= $nb; ++$i) {
1571+
$internalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser();
1572+
$internalUser->setFirstname('Internal');
1573+
$internalUser->setLastname('User');
1574+
$internalUser->setEmail('[email protected]');
1575+
$internalUser->setInternalId('INT');
1576+
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
1577+
$site->setTitle('title');
1578+
$site->setDescription('description');
1579+
$site->setOwner($internalUser);
1580+
$this->manager->persist($site);
1581+
}
1582+
$this->manager->flush();
1583+
}
1584+
1585+
/**
1586+
* @Given there are :nb sites with external owner
1587+
*/
1588+
public function thereAreSitesWithExternalOwner(int $nb)
1589+
{
1590+
for ($i = 1; $i <= $nb; ++$i) {
1591+
$externalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser();
1592+
$externalUser->setFirstname('External');
1593+
$externalUser->setLastname('User');
1594+
$externalUser->setEmail('[email protected]');
1595+
$externalUser->setExternalId('EXT');
1596+
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
1597+
$site->setTitle('title');
1598+
$site->setDescription('description');
1599+
$site->setOwner($externalUser);
1600+
$this->manager->persist($site);
1601+
}
1602+
$this->manager->flush();
1603+
}
15431604
}

features/main/operation.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Operation support
44
I need to be able to add custom operations and remove built-in ones
55

66
@createSchema
7-
@dropSchema
87
Scenario: Can not write readonly property
98
When I add "Content-Type" header equal to "application/ld+json"
109
And I send a "POST" request to "/readable_only_properties" with body:

features/main/relation.feature

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ Feature: Relations support
491491
Given there are people having pets
492492
When I add "Content-Type" header equal to "application/ld+json"
493493
And I send a "GET" request to "/people"
494-
And the response status code should be 200
494+
Then the response status code should be 200
495495
And the response should be in JSON
496496
And the JSON should be equal to:
497497
"""
@@ -621,8 +621,6 @@ Feature: Relations support
621621
}
622622
"""
623623

624-
625-
@dropSchema
626624
Scenario: Passing an invalid IRI to a relation
627625
When I add "Content-Type" header equal to "application/ld+json"
628626
And I send a "POST" request to "/relation_embedders" with body:
@@ -634,7 +632,7 @@ Feature: Relations support
634632
Then the response status code should be 400
635633
And the response should be in JSON
636634
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
637-
And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)."
635+
And the JSON node "hydra:description" should contain 'Invalid IRI "certainly not an iri and not a plain identifier".'
638636

639637
Scenario: Passing an invalid type to a relation
640638
When I add "Content-Type" header equal to "application/ld+json"
@@ -647,4 +645,32 @@ Feature: Relations support
647645
Then the response status code should be 400
648646
And the response should be in JSON
649647
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
650-
And the JSON node "hydra:description" should contain "Invalid value provided (invalid IRI?)."
648+
And the JSON should be valid according to this schema:
649+
"""
650+
{
651+
"type": "object",
652+
"properties": {
653+
"@context": {
654+
"type": "string",
655+
"pattern": "^/contexts/Error$"
656+
},
657+
"@type": {
658+
"type": "string",
659+
"pattern": "^hydra:Error$"
660+
},
661+
"hydra:title": {
662+
"type": "string",
663+
"pattern": "^An error occurred$"
664+
},
665+
"hydra:description": {
666+
"pattern": "^Expected IRI or document for resource \"ApiPlatform\\\\Core\\\\Tests\\\\Fixtures\\\\TestBundle\\\\(Document|Entity)\\\\RelatedDummy\", \"integer\" given.$"
667+
}
668+
},
669+
"required": [
670+
"@context",
671+
"@type",
672+
"hydra:title",
673+
"hydra:description"
674+
]
675+
}
676+
"""

0 commit comments

Comments
 (0)