Skip to content

Commit 9f47142

Browse files
committed
add behat tests
1 parent a6cd704 commit 9f47142

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Question;
4444
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RamseyUuidDummy;
4545
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
46+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedOwnedDummy;
47+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedOwningDummy;
4648
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedToDummyFriend;
4749
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelationEmbedder;
4850
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\SecuredDummy;
@@ -1007,6 +1009,21 @@ public function thereIsADummyObjectWithAFourthLevelRelation()
10071009
$this->manager->flush();
10081010
}
10091011

1012+
/**
1013+
* @Given there is a RelatedOwnedDummy and a RelatedOwningDummy object with OneToOne bidirectional relation
1014+
*/
1015+
public function thereIsARelatedOwnedDummyAndARelatedOwningDummy()
1016+
{
1017+
$relatedOwnedDummy = new RelatedOwnedDummy();
1018+
$this->manager->persist($relatedOwnedDummy);
1019+
1020+
$relatedOwningDummy = new RelatedOwningDummy();
1021+
$relatedOwningDummy->setOwnedDummy($relatedOwnedDummy);
1022+
$this->manager->persist($relatedOwningDummy);
1023+
1024+
$this->manager->flush();
1025+
}
1026+
10101027
/**
10111028
* @Given there is a person named :name greeting with a :message message
10121029
*/

features/main/subresource.feature

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Feature: Subresource support
350350
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
351351
And the JSON should be equal to:
352352
"""
353-
{
353+
{+
354354
"@context": "/contexts/DummyProduct",
355355
"@id": "/dummy_products/2",
356356
"@type": "DummyProduct",
@@ -365,3 +365,37 @@ Feature: Subresource support
365365
"parent": null
366366
}
367367
"""
368+
369+
@dropSchema
370+
Scenario: The OneToOne subresource should be accessible from owned side
371+
Given there is a RelatedOwnedDummy and a RelatedOwningDummy object with OneToOne bidirectional relation
372+
When I send a "GET" request to "/related_owned_dummies/1/related_owning_dummy"
373+
And the response status code should be 200
374+
And the response should be in JSON
375+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
376+
And the JSON should be equal to:
377+
"""
378+
{
379+
"@context": "/contexts/RelatedOwningDummy",
380+
"@id": "/related_owning_dummies/1",
381+
"@type": "RelatedOwningDummy",
382+
"id": 1
383+
}
384+
"""
385+
386+
@dropSchema
387+
Scenario: The OneToOne subresource should be accessible from owning side
388+
Given there is a RelatedOwnedDummy and a RelatedOwningDummy object with OneToOne bidirectional relation
389+
When I send a "GET" request to "/related_owning_dummies/1/related_owned_dummy"
390+
And the response status code should be 200
391+
And the response should be in JSON
392+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
393+
And the JSON should be equal to:
394+
"""
395+
{
396+
"@context": "/contexts/RelatedOwnedDummy",
397+
"@id": "/related_owned_dummies/1",
398+
"@type": "RelatedOwnedDummy",
399+
"id": 1
400+
}
401+
"""

0 commit comments

Comments
 (0)