Skip to content

Commit

Permalink
Merge 52a7bdf into 39900b9
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek- committed Apr 15, 2019
2 parents 39900b9 + 52a7bdf commit 9430f00
Show file tree
Hide file tree
Showing 18 changed files with 416 additions and 46 deletions.
21 changes: 21 additions & 0 deletions features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyOffer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProduct;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProperty;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyTableInheritanceNotApiResourceChild as DummyTableInheritanceNotApiResourceChildDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
Expand Down Expand Up @@ -165,6 +167,17 @@ public function thereAreDummyObjects(int $nb)
$this->manager->flush();
}

/**
* @When some dummy table inheritance data but not api resource child are created
*/
public function someDummyTableInheritanceDataButNotApiResourceChildAreCreated()
{
$dummy = $this->buildDummyTableInheritanceNotApiResourceChild();
$dummy->setName('Foobarbaz inheritance');
$this->manager->persist($dummy);
$this->manager->flush();
}

/**
* @Given there are :nb foo objects with fake names
*/
Expand Down Expand Up @@ -1272,6 +1285,14 @@ private function buildDummy()
return $this->isOrm() ? new Dummy() : new DummyDocument();
}

/**
* @return DummyTableInheritanceNotApiResourceChild|DummyTableInheritanceNotApiResourceChildDocument
*/
private function buildDummyTableInheritanceNotApiResourceChild()
{
return $this->isOrm() ? new DummyTableInheritanceNotApiResourceChild() : new DummyTableInheritanceNotApiResourceChildDocument();
}

/**
* @return DummyAggregateOffer|DummyAggregateOfferDocument
*/
Expand Down
134 changes: 115 additions & 19 deletions features/main/table_inheritance.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceChild$"
"pattern": "^DummyTableInheritanceChild$",
"required": "true"
},
"@context": {
"type": "string",
"pattern": "^/contexts/DummyTableInheritanceChild$"
"pattern": "^/contexts/DummyTableInheritanceChild$",
"required": "true"
},
"@id": {
"type": "string",
"pattern": "^/dummy_table_inheritance_children/1$"
"pattern": "^/dummy_table_inheritance_children/1$",
"required": "true"
},
"name": {
"type": "string",
Expand Down Expand Up @@ -61,7 +64,8 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceChild$"
"pattern": "^DummyTableInheritanceChild$",
"required": "true"
},
"name": {
"type": "string",
Expand All @@ -80,7 +84,40 @@ Feature: Table inheritance
}
"""

@createSchema
Scenario: Some children not api resources are created in the app
When some dummy table inheritance data but not api resource child are created
And I send a "GET" request to "/dummy_table_inheritances"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be valid according to this schema:
"""
{
"type": "object",
"properties": {
"hydra:member": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritance(Child)?$",
"required": "true"
},
"name": {
"type": "string",
"required": "true"
}
}
},
"minItems": 1
}
},
"required": ["hydra:member"]
}
"""

Scenario: Create a table inherited resource
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/dummy_table_inheritance_children" with body:
Expand All @@ -97,15 +134,18 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceChild$"
"pattern": "^DummyTableInheritanceChild$",
"required": "true"
},
"@context": {
"type": "string",
"pattern": "^/contexts/DummyTableInheritanceChild$"
"pattern": "^/contexts/DummyTableInheritanceChild$",
"required": "true"
},
"@id": {
"type": "string",
"pattern": "^/dummy_table_inheritance_children/1$"
"pattern": "^/dummy_table_inheritance_children/3$",
"required": "true"
},
"name": {
"type": "string",
Expand Down Expand Up @@ -136,15 +176,18 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceDifferentChild$"
"pattern": "^DummyTableInheritanceDifferentChild$",
"required": "true"
},
"@context": {
"type": "string",
"pattern": "^/contexts/DummyTableInheritanceDifferentChild$"
"pattern": "^/contexts/DummyTableInheritanceDifferentChild$",
"required": "true"
},
"@id": {
"type": "string",
"pattern": "^/dummy_table_inheritance_different_children/2$"
"pattern": "^/dummy_table_inheritance_different_children/4$",
"required": "true"
},
"name": {
"type": "string",
Expand All @@ -167,7 +210,7 @@ Feature: Table inheritance
{
"children": [
"/dummy_table_inheritance_children/1",
"/dummy_table_inheritance_different_children/2"
"/dummy_table_inheritance_different_children/4"
]
}
"""
Expand All @@ -181,15 +224,18 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceRelated$"
"pattern": "^DummyTableInheritanceRelated$",
"required": "true"
},
"@context": {
"type": "string",
"pattern": "^/contexts/DummyTableInheritanceRelated$"
"pattern": "^/contexts/DummyTableInheritanceRelated$",
"required": "true"
},
"@id": {
"type": "string",
"pattern": "^/dummy_table_inheritance_relateds/1$"
"pattern": "^/dummy_table_inheritance_relateds/1$",
"required": "true"
},
"children": {
"items": {
Expand All @@ -199,7 +245,8 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceChild$"
"pattern": "^DummyTableInheritanceChild$",
"required": "true"
},
"name": {
"type": "string",
Expand All @@ -215,7 +262,21 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceDifferentChild$"
"pattern": "^DummyTableInheritance$",
"required": "true"
},
"name": {
"type": "string",
"required": "true"
}
}
},
{
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceDifferentChild$",
"required": "true"
},
"name": {
"type": "string",
Expand Down Expand Up @@ -255,7 +316,8 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceChild$"
"pattern": "^DummyTableInheritanceChild$",
"required": "true"
},
"name": {
"type": "string",
Expand All @@ -271,7 +333,21 @@ Feature: Table inheritance
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceDifferentChild$"
"pattern": "^DummyTableInheritance$",
"required": "true"
},
"name": {
"type": "string",
"required": "true"
}
}
},
{
"properties": {
"@type": {
"type": "string",
"pattern": "^DummyTableInheritanceDifferentChild$",
"required": "true"
},
"name": {
"type": "string",
Expand Down Expand Up @@ -307,6 +383,16 @@ Feature: Table inheritance
"items": {
"type": "object",
"properties": {
"@type": {
"type": "string",
"pattern": "^ResourceInterface$",
"required": "true"
},
"@id": {
"type": "string",
"pattern": "^/resource_interfaces/",
"required": "true"
},
"foo": {
"type": "string",
"required": "true"
Expand Down Expand Up @@ -338,6 +424,16 @@ Feature: Table inheritance
"type": "string",
"pattern": "ResourceInterface$"
},
"@id": {
"type": "string",
"pattern": "^/resource_interfaces",
"required": "true"
},
"@type": {
"type": "string",
"pattern": "^ResourceInterface$",
"required": "true"
},
"foo": {
"type": "string",
"required": "true"
Expand Down
4 changes: 4 additions & 0 deletions src/Api/IdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function getIdentifiersFromItem($item): array
{
$identifiers = [];
$resourceClass = $this->getObjectClass($item);
if (null !== $this->resourceClassResolver) { // BC Layer
$resourceClass = $this->resourceClassResolver->isResourceClass($resourceClass) ? $this->resourceClassResolver->getResourceClass($item) : $resourceClass;
}

foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
$identifier = $propertyMetadata->isIdentifier();
Expand Down
6 changes: 6 additions & 0 deletions src/Api/IriConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Converts item and resources to IRI and vice versa.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @deprecated in favor of ResourceIriConverterInterface to be removed in ApiPlatform 3.0
*/
interface IriConverterInterface
{
Expand All @@ -41,6 +43,10 @@ public function getItemFromIri(string $iri, array $context = []);
*
* @throws InvalidArgumentException
* @throws RuntimeException
*
* @return string Class name of resource
*
* @deprecated in favor of `ResourceIriConverterInterface::getIriFromItemWithResource`
*/
public function getIriFromItem($item, int $referenceType = UrlGeneratorInterface::ABS_PATH): string;

Expand Down
Loading

0 comments on commit 9430f00

Please sign in to comment.