-
-
Notifications
You must be signed in to change notification settings - Fork 940
Fix serialization when using interface as resource #2822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
teohhanhui
merged 1 commit into
api-platform:2.4
from
teohhanhui:fix/serializer-readable-writable-link
Jun 8, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,13 +44,15 @@ | |
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Person as PersonDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\PersonToPet as PersonToPetDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Pet as PetDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Product as ProductDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Question as QuestionDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedDummy as RelatedDummyDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedOwnedDummy as RelatedOwnedDummyDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedOwningDummy as RelatedOwningDummyDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedToDummyFriend as RelatedToDummyFriendDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelationEmbedder as RelationEmbedderDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\SecuredDummy as SecuredDummyDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Taxon as TaxonDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ThirdLevel as ThirdLevelDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\User as UserDocument; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Address; | ||
|
|
@@ -78,17 +80,20 @@ | |
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Foo; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FooDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FourthLevel; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Greeting; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MaxDepthDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Node; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Order; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Person; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\PersonToPet; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Pet; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Product; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Question; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RamseyUuidDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy; | ||
|
|
@@ -97,10 +102,13 @@ | |
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedToDummyFriend; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelationEmbedder; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\SecuredDummy; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Taxon; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ThirdLevel; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User; | ||
| use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UuidIdentifierDummy; | ||
| use Behat\Behat\Context\Context; | ||
| use Behat\Gherkin\Node\PyStringNode; | ||
| use Doctrine\Common\Persistence\ManagerRegistry; | ||
| use Doctrine\ODM\MongoDB\DocumentManager; | ||
| use Doctrine\ORM\EntityManagerInterface; | ||
|
|
@@ -1227,6 +1235,108 @@ public function thereAreNbDummyDtoCustom($nb) | |
| $this->manager->clear(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there is an order with same customer and recipient | ||
| */ | ||
| public function thereIsAnOrderWithSameCustomerAndRecipient() | ||
| { | ||
| $customer = $this->isOrm() ? new Customer() : new CustomerDocument(); | ||
| $customer->name = 'customer_name'; | ||
|
|
||
| $address1 = $this->isOrm() ? new Address() : new AddressDocument(); | ||
| $address1->name = 'foo'; | ||
| $address2 = $this->isOrm() ? new Address() : new AddressDocument(); | ||
| $address2->name = 'bar'; | ||
|
|
||
| $order = $this->isOrm() ? new Order() : new OrderDocument(); | ||
| $order->recipient = $customer; | ||
| $order->customer = $customer; | ||
|
|
||
| $customer->addresses->add($address1); | ||
| $customer->addresses->add($address2); | ||
|
|
||
| $this->manager->persist($address1); | ||
| $this->manager->persist($address2); | ||
| $this->manager->persist($customer); | ||
| $this->manager->persist($order); | ||
|
|
||
| $this->manager->flush(); | ||
| $this->manager->clear(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there are :nb sites with internal owner | ||
| */ | ||
| public function thereAreSitesWithInternalOwner(int $nb) | ||
| { | ||
| for ($i = 1; $i <= $nb; ++$i) { | ||
| $internalUser = new InternalUser(); | ||
| $internalUser->setFirstname('Internal'); | ||
| $internalUser->setLastname('User'); | ||
| $internalUser->setEmail('[email protected]'); | ||
| $internalUser->setInternalId('INT'); | ||
| $site = new Site(); | ||
| $site->setTitle('title'); | ||
| $site->setDescription('description'); | ||
| $site->setOwner($internalUser); | ||
| $this->manager->persist($site); | ||
| } | ||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there are :nb sites with external owner | ||
| */ | ||
| public function thereAreSitesWithExternalOwner(int $nb) | ||
| { | ||
| for ($i = 1; $i <= $nb; ++$i) { | ||
| $externalUser = new ExternalUser(); | ||
| $externalUser->setFirstname('External'); | ||
| $externalUser->setLastname('User'); | ||
| $externalUser->setEmail('[email protected]'); | ||
| $externalUser->setExternalId('EXT'); | ||
| $site = new Site(); | ||
| $site->setTitle('title'); | ||
| $site->setDescription('description'); | ||
| $site->setOwner($externalUser); | ||
| $this->manager->persist($site); | ||
| } | ||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there is the following taxon: | ||
| */ | ||
| public function thereIsTheFollowingTaxon(PyStringNode $dataNode): void | ||
| { | ||
| $data = json_decode((string) $dataNode, true); | ||
|
|
||
| $taxon = $this->isOrm() ? new Taxon() : new TaxonDocument(); | ||
| $taxon->setCode($data['code']); | ||
| $this->manager->persist($taxon); | ||
|
|
||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there is the following product: | ||
| */ | ||
| public function thereIsTheFollowingProduct(PyStringNode $dataNode): void | ||
| { | ||
| $data = json_decode((string) $dataNode, true); | ||
|
|
||
| $product = $this->isOrm() ? new Product() : new ProductDocument(); | ||
| $product->setCode($data['code']); | ||
| if (isset($data['mainTaxon'])) { | ||
| $mainTaxonId = (int) str_replace('/taxons/', '', $data['mainTaxon']); | ||
| $mainTaxon = $this->manager->getRepository($this->isOrm() ? Taxon::class : TaxonDocument::class)->find($mainTaxonId); | ||
| $product->setMainTaxon($mainTaxon); | ||
| } | ||
| $this->manager->persist($product); | ||
|
|
||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| private function isOrm(): bool | ||
| { | ||
| return null !== $this->schemaTool; | ||
|
|
@@ -1532,73 +1642,4 @@ private function buildThirdLevel() | |
| { | ||
| return $this->isOrm() ? new ThirdLevel() : new ThirdLevelDocument(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there is a order with same customer and receiver | ||
| */ | ||
| public function testEagerLoadingNotDuplicateRelation() | ||
| { | ||
| $customer = $this->isOrm() ? new Customer() : new CustomerDocument(); | ||
| $customer->name = 'customer_name'; | ||
|
|
||
| $address1 = $this->isOrm() ? new Address() : new AddressDocument(); | ||
| $address1->name = 'foo'; | ||
| $address2 = $this->isOrm() ? new Address() : new AddressDocument(); | ||
| $address2->name = 'bar'; | ||
|
|
||
| $order = $this->isOrm() ? new Order() : new OrderDocument(); | ||
| $order->recipient = $customer; | ||
| $order->customer = $customer; | ||
|
|
||
| $customer->addresses->add($address1); | ||
| $customer->addresses->add($address2); | ||
|
|
||
| $this->manager->persist($address1); | ||
| $this->manager->persist($address2); | ||
| $this->manager->persist($customer); | ||
| $this->manager->persist($order); | ||
|
|
||
| $this->manager->flush(); | ||
| $this->manager->clear(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there are :nb sites with internal owner | ||
| */ | ||
| public function thereAreSitesWithInternalOwner(int $nb) | ||
| { | ||
| for ($i = 1; $i <= $nb; ++$i) { | ||
| $internalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser(); | ||
| $internalUser->setFirstname('Internal'); | ||
| $internalUser->setLastname('User'); | ||
| $internalUser->setEmail('[email protected]'); | ||
| $internalUser->setInternalId('INT'); | ||
| $site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site(); | ||
| $site->setTitle('title'); | ||
| $site->setDescription('description'); | ||
| $site->setOwner($internalUser); | ||
| $this->manager->persist($site); | ||
| } | ||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| /** | ||
| * @Given there are :nb sites with external owner | ||
| */ | ||
| public function thereAreSitesWithExternalOwner(int $nb) | ||
| { | ||
| for ($i = 1; $i <= $nb; ++$i) { | ||
| $externalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser(); | ||
| $externalUser->setFirstname('External'); | ||
| $externalUser->setLastname('User'); | ||
| $externalUser->setEmail('[email protected]'); | ||
| $externalUser->setExternalId('EXT'); | ||
| $site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site(); | ||
| $site->setTitle('title'); | ||
| $site->setDescription('description'); | ||
| $site->setOwner($externalUser); | ||
| $this->manager->persist($site); | ||
| } | ||
| $this->manager->flush(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| Feature: JSON-LD using interface as resource | ||
| In order to use interface as resource | ||
| As a developer | ||
| I should be able to serialize objects of an interface as API resource. | ||
|
|
||
| Background: | ||
| Given I add "Accept" header equal to "application/ld+json" | ||
| And I add "Content-Type" header equal to "application/ld+json" | ||
|
|
||
| @createSchema | ||
| Scenario: Retrieve a taxon | ||
| Given there is the following taxon: | ||
| """ | ||
| { | ||
| "code": "WONDERFUL_TAXON" | ||
| } | ||
| """ | ||
| When I send a "GET" request to "/taxons/1" | ||
| 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 equal to: | ||
| """ | ||
| { | ||
| "@context": "/contexts/Taxon", | ||
| "@id": "/taxons/1", | ||
| "@type": "Taxon", | ||
| "code": "WONDERFUL_TAXON" | ||
| } | ||
| """ | ||
|
|
||
| Scenario: Retrieve a product with a main taxon | ||
| Given there is the following product: | ||
| """ | ||
| { | ||
| "code": "GREAT_PRODUCT", | ||
| "mainTaxon": "/taxons/1" | ||
| } | ||
| """ | ||
| When I send a "GET" request to "/products/1" | ||
| 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 equal to: | ||
| """ | ||
| { | ||
| "@context": "/contexts/Product", | ||
| "@id": "/products/1", | ||
| "@type": "Product", | ||
| "code": "GREAT_PRODUCT", | ||
| "mainTaxon": { | ||
| "@id": "/taxons/1", | ||
| "@type": "Taxon", | ||
| "code": "WONDERFUL_TAXON" | ||
| } | ||
| } | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.