Skip to content

Commit cd8c672

Browse files
committed
#35906 GraphQL Routes query with fragments has issue in the category page #35906
- Test fixes adapted for the new version of webonyx/graphql-php
1 parent 7858097 commit cd8c672

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

app/code/Magento/CatalogGraphQl/Test/Unit/Model/Resolver/Category/DepthCalculatorTest.php

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class DepthCalculatorTest extends TestCase
4141
public function testCalculateWithNullAsSelectionSet(): void
4242
{
4343
$this->fieldNodeMock->kind = NodeKind::FIELD;
44-
/** @var SelectionSetNode $selectionSetMock */
45-
$selectionSetMock = $this->createMock(SelectionSetNode::class);
46-
$selectionSetMock->selections = $this->getMockSelectionsArrayForNullCase();
47-
$this->fieldNodeMock->selectionSet = $selectionSetMock;
44+
/** @var SelectionSetNode $selectionSetNode */
45+
$selectionSetNode = new SelectionSetNode([]);
46+
$selectionSetNode->selections = $this->getSelectionsArrayForNullCase();
47+
$this->fieldNodeMock->selectionSet = $selectionSetNode;
4848
$result = $this->depthCalculator->calculate($this->resolveInfoMock, $this->fieldNodeMock);
49-
$this->assertEquals(1, $result);
49+
$this->assertSame(1, $result);
5050
}
5151

5252
/**
@@ -56,66 +56,60 @@ public function testCalculateWithNullAsSelectionSet(): void
5656
public function testCalculateNonNullAsSelectionSet(): void
5757
{
5858
$this->fieldNodeMock->kind = NodeKind::FIELD;
59-
$selectionSetMock = $this->createMock(SelectionSetNode::class);
60-
$selectionSetMock->selections = $this->getMockSelectionsArrayForNonNullCase();
61-
$this->fieldNodeMock->selectionSet = $selectionSetMock;
59+
$selectionSetNode = $this->getSelectionSetNode();
60+
$selectionSetNode->selections = $this->getSelectionsArrayForNonNullCase();
61+
$this->fieldNodeMock->selectionSet = $selectionSetNode;
6262
$result = $this->depthCalculator->calculate($this->resolveInfoMock, $this->fieldNodeMock);
6363
$this->assertEquals(2, $result);
6464
}
6565

6666
/**
6767
* @return NodeList
6868
*/
69-
private function getMockSelectionsArrayForNullCase()
69+
private function getSelectionsArrayForNullCase()
7070
{
71-
/** @var SelectionSetNode $selectionSetMock */
72-
$selectionSetMock = $this->createMock(SelectionSetNode::class);
73-
$selectionSetMock->selections = [$this->getNewFieldNodeMock()];
74-
$inlineFragmentMock = $this->getNewInlineFragmentNodeMock();
75-
$inlineFragmentMock->selectionSet = $selectionSetMock;
71+
$selectionSetNode = $this->getSelectionSetNode();
72+
$selectionSetNode->selections = $this->getNodeList();
73+
$inlineFragmentNode = $this->getNewInlineFragmentNode();
74+
$inlineFragmentNode->selectionSet = $selectionSetNode;
7675
return new NodeList([
77-
$this->getNewFieldNodeMock(),
78-
$inlineFragmentMock
76+
$this->getNewFieldNode(),
77+
$inlineFragmentNode
7978
]);
8079
}
8180

8281
/**
83-
* @return FieldNode|MockObject
82+
* @return FieldNode
8483
*/
85-
private function getNewFieldNodeMock()
84+
private function getNewFieldNode()
8685
{
87-
return $this->getMockBuilder(FieldNode::class)
88-
->setConstructorArgs(['vars' => []])
89-
->getMock();
86+
return new FieldNode([]);
9087
}
9188

9289
/**
93-
* @return InlineFragmentNode|MockObject
90+
* @return InlineFragmentNode
9491
*/
95-
private function getNewInlineFragmentNodeMock()
92+
private function getNewInlineFragmentNode()
9693
{
97-
return $this->getMockBuilder(InlineFragmentNode::class)
98-
->disableOriginalConstructor()
99-
->getMock();
94+
return new InlineFragmentNode([]);
10095
}
10196

10297
/**
10398
* @return NodeList
10499
*/
105-
private function getMockSelectionsArrayForNonNullCase()
100+
private function getSelectionsArrayForNonNullCase()
106101
{
107-
$newFieldMock = $this->getNewFieldNodeMock();
108-
$newFieldMock->selectionSet = $this->createMock(SelectionSetNode::class);
109-
$newFieldMock->selectionSet->selections = [$this->getNewFieldNodeMock()];
110-
/** @var SelectionSetNode $selectionSetMock */
111-
$selectionSetMock = $this->createMock(SelectionSetNode::class);
112-
$selectionSetMock->selections = [$newFieldMock];
113-
114-
$inlineFragmentMock = $this->getNewInlineFragmentNodeMock();
115-
$inlineFragmentMock->selectionSet = $selectionSetMock;
102+
$newFieldNode = $this->getNewFieldNode();
103+
$newFieldNode->selectionSet = $this->getSelectionSetNode();
104+
$newFieldNode->selectionSet->selections = $this->getNodeList();
105+
$newFieldNode->selectionSet->selections[] = $this->getNewFieldNode();
106+
$selectionSetNode = $this->getSelectionSetNode();
107+
$selectionSetNode->selections = new NodeList([$newFieldNode]);
108+
$inlineFragmentNode = $this->getNewInlineFragmentNode();
109+
$inlineFragmentNode->selectionSet = $selectionSetNode;
116110
return new NodeList([
117-
$this->getNewFieldNodeMock(),
118-
$inlineFragmentMock
111+
$newFieldNode,
112+
$inlineFragmentNode
119113
]);
120114
}
121115

@@ -130,4 +124,20 @@ protected function setUp(): void
130124
->disableOriginalConstructor()
131125
->getMock();
132126
}
127+
128+
/**
129+
* @return \GraphQL\Language\AST\SelectionSetNode
130+
*/
131+
protected function getSelectionSetNode($nodes = []): SelectionSetNode
132+
{
133+
return new SelectionSetNode($nodes);
134+
}
135+
136+
/**
137+
* @return \GraphQL\Language\AST\NodeList
138+
*/
139+
protected function getNodeList(): NodeList
140+
{
141+
return new NodeList([]);
142+
}
133143
}

0 commit comments

Comments
 (0)