Skip to content

Commit

Permalink
test: do not rely on order of insertion (api-platform#5709)
Browse files Browse the repository at this point in the history
* fix: add conflict on doctrine/orm:2.16.0

See doctrine/orm#10547

* fix: extend above 2.16 as 2.17 is bugged too

* fix(maxdepthEager): relying on node existance instead of the full representation

* fix: correction for more insert order checks

* fix: correction for more insert order checks

* fix: typo
  • Loading branch information
GregoireHebert authored and Romaixn committed Oct 3, 2023
1 parent 130eb6f commit a2472a7
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 156 deletions.
8 changes: 4 additions & 4 deletions features/graphql/query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Feature: GraphQL query support
And the JSON node "data.multiRelationsDummy.manyToOneRelation.name" should be equal to "RelatedManyToOneDummy #2"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges" should have 2 element
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.id" should not be null
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[0].node.name" should be equal to "RelatedManyToManyDummy12"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.name" should be equal to "RelatedManyToManyDummy22"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[0].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
And the JSON node "data.multiRelationsDummy.manyToManyRelations.edges[1].node.name" should match "#RelatedManyToManyDummy(1|2)2#"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges" should have 3 element
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[1].node.id" should not be null
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[0].node.name" should be equal to "RelatedOneToManyDummy12"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[2].node.name" should be equal to "RelatedOneToManyDummy32"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[0].node.name" should match "#RelatedOneToManyDummy(1|3)2#"
And the JSON node "data.multiRelationsDummy.oneToManyRelations.edges[2].node.name" should match "#RelatedOneToManyDummy(1|3)2#"

@createSchema @!mongodb
Scenario: Retrieve an item with child relation to the same resource
Expand Down
99 changes: 15 additions & 84 deletions features/hal/max_depth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,33 @@ Feature: Max depth handling
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/hal+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"_links": {
"self": {
"href": "/max_depth_eager_dummies/1"
},
"child": {
"href": "/max_depth_eager_dummies/2"
}
},
"_embedded": {
"child": {
"_links": {
"self": {
"href": "/max_depth_eager_dummies/2"
}
},
"id": 2,
"name": "level 2"
}
},
"id": 1,
"name": "level 1"
}
"""
Then the JSON node "_embedded" should exist
Then the JSON node "_embedded.child" should exist
Then the JSON node "_embedded.child._embedded" should not exist

Scenario: Add a 2nd level of descendants
Scenario: Create a resource with 2 levels of descendants
When I add "Accept" header equal to "application/hal+json"
And I add "Content-Type" header equal to "application/json"
And I send a "PUT" request to "max_depth_eager_dummies/1" with body:
And I send a "POST" request to "/max_depth_eager_dummies" with body:
"""
{
"id": "/max_depth_eager_dummies/1",
"name": "level 1",
"child": {
"id": "/max_depth_eager_dummies/2",
"name": "level 2",
"child": {
"name": "level 3"
}
}
}
"""
And the response status code should be 200
And the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/hal+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"_links": {
"self": {
"href": "/max_depth_eager_dummies/1"
},
"child": {
"href": "/max_depth_eager_dummies/2"
}
},
"_embedded": {
"child": {
"_links": {
"self": {
"href": "/max_depth_eager_dummies/2"
}
},
"id": 2,
"name": "level 2"
}
},
"id": 1,
"name": "level 1"
}
"""
Then the JSON node "_embedded" should exist
Then the JSON node "_embedded.child" should exist
Then the JSON node "_embedded.child._embedded" should not exist

Scenario: Add a 2nd level of descendants when eager fetching is disabled
Scenario: Create a resource with 1 levels of descendants then add a 2nd level of descendants when eager fetching is disabled
Given there is a max depth dummy with 1 level of descendants
When I add "Accept" header equal to "application/hal+json"
And I add "Content-Type" header equal to "application/json"
Expand All @@ -110,29 +64,6 @@ Feature: Max depth handling
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/hal+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"_links": {
"self": {
"href": "/max_depth_dummies/1"
},
"child": {
"href": "/max_depth_dummies/2"
}
},
"_embedded": {
"child": {
"_links": {
"self": {
"href": "/max_depth_dummies/2"
}
},
"id": 2,
"name": "level 2"
}
},
"id": 1,
"name": "level 1"
}
"""
Then the JSON node "_embedded" should exist
Then the JSON node "_embedded.child" should exist
Then the JSON node "_embedded.child._embedded" should not exist
33 changes: 4 additions & 29 deletions features/jsonapi/collection_attributes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,7 @@ Feature: JSON API collections support
Then the response status code should be 200
And the response should be in JSON
And the JSON should be valid according to the JSON API schema
And the JSON should be equal to:
"""
{
"data": {
"id": "/circular_references/1",
"type": "CircularReference",
"relationships": {
"parent": {
"data": {
"type": "CircularReference",
"id": "/circular_references/1"
}
},
"children": {
"data": [
{
"type": "CircularReference",
"id": "/circular_references/1"
},
{
"type": "CircularReference",
"id": "/circular_references/2"
}
]
}
}
}
}
"""
And the JSON node "data.id" should be equal to "/circular_references/1"
And the JSON node "data.relationships.parent.data.id" should be equal to "/circular_references/1"
And the JSON node "data.relationships.children.data[0].id" should match "#/circular_references/(1|2)#"
And the JSON node "data.relationships.children.data[1].id" should match "#/circular_references/(1|2)#"
46 changes: 9 additions & 37 deletions features/jsonld/max_depth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,26 @@ Feature: Max depth handling
Then the response status code should be 201
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/MaxDepthEagerDummy",
"@id": "/max_depth_eager_dummies/1",
"@type": "MaxDepthEagerDummy",
"id": 1,
"name": "level 1",
"child": {
"@id": "/max_depth_eager_dummies/2",
"@type": "MaxDepthEagerDummy",
"id": 2,
"name": "level 2"
}
}
"""
Then the JSON node "child" should exist
Then the JSON node "child.name" should be equal to "level 2"

Scenario: Add a 2nd level of descendants
When I add "Content-Type" header equal to "application/ld+json"
And I send a "PUT" request to "max_depth_eager_dummies/1" with body:
And I send a "POST" request to "/max_depth_eager_dummies" with body:
"""
{
"@id": "/max_depth_eager_dummies/1",
"name": "level 1",
"child": {
"@id": "/max_depth_eager_dummies/2",
"name": "level 2",
"child": {
"name": "level 3"
}
}
}
"""
And the response status code should be 200
And the response status code should be 201
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/MaxDepthEagerDummy",
"@id": "/max_depth_eager_dummies/1",
"@type": "MaxDepthEagerDummy",
"id": 1,
"name": "level 1",
"child": {
"@id": "/max_depth_eager_dummies/2",
"@type": "MaxDepthEagerDummy",
"id": 2,
"name": "level 2"
}
}
"""

Then the JSON node "child" should exist
Then the JSON node "child.name" should be equal to "level 2"
Then the JSON node "child.child" should not exist
4 changes: 4 additions & 0 deletions tests/Behat/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1483,17 +1483,21 @@ public function thePasswordForUserShouldBeHashed(string $password, string $user)
public function createProductWithOffers(): void
{
$offer = $this->buildDummyOffer();
$offer->setId(1);
$offer->setValue(2);

$aggregate = $this->buildDummyAggregateOffer();
$aggregate->setValue(1);
$aggregate->addOffer($offer);

$product = $this->buildDummyProduct();
$product->setId(2);
$product->setName('Dummy product');
$product->addOffer($aggregate);

$relatedProduct = $this->buildDummyProduct();
$relatedProduct->setName('Dummy related product');
$relatedProduct->setId(1);
$relatedProduct->setParent($product);

$product->addRelatedProduct($relatedProduct);
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/TestBundle/Document/DummyOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function getId(): ?int
return $this->id;
}

public function setId(int $id): void
{
$this->id = $id;
}

public function getValue(): int
{
return $this->value;
Expand Down
7 changes: 6 additions & 1 deletion tests/Fixtures/TestBundle/Document/DummyProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DummyProduct
/**
* @var int The id
*/
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
#[ODM\Id(strategy: 'None', type: 'int')]
private ?int $id = null;
#[ODM\ReferenceMany(targetDocument: DummyAggregateOffer::class, mappedBy: 'product', cascade: ['persist'])]
private Collection|iterable $offers;
Expand Down Expand Up @@ -76,6 +76,11 @@ public function getId(): ?int
return $this->id;
}

public function setId(int $id): void
{
$this->id = $id;
}

public function getName(): string
{
return $this->name;
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/TestBundle/Entity/DummyOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function getId(): ?int
return $this->id;
}

public function setId(int $id): void
{
$this->id = $id;
}

public function getValue(): int
{
return $this->value;
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/TestBundle/Entity/DummyProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class DummyProduct
*/
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
/**
* @var Collection<int, DummyAggregateOffer>
Expand Down Expand Up @@ -84,6 +83,11 @@ public function getId(): ?int
return $this->id;
}

public function setId(int $id): void
{
$this->id = $id;
}

public function getName(): string
{
return $this->name;
Expand Down

0 comments on commit a2472a7

Please sign in to comment.