Skip to content
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

fix: change tests to not rely on order of insertion #5709

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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