Skip to content

Commit 0adcc13

Browse files
authored
Merge pull request #554 from magento-performance/ACPT-1388
ACPT-1388: Add queries to GraphQlStateTest
2 parents 6da40ce + 7ea9e09 commit 0adcc13

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

dev/tests/integration/testsuite/Magento/GraphQl/App/GraphQlStateTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,19 @@ protected function setUp(): void
5151

5252
/**
5353
* Runs various GraphQL queries and checks if state of shared objects in Object Manager have changed
54-
*
54+
* @magentoConfigFixture base_website btob/website_configuration/company_active 1
55+
* @magentoConfigFixture default_store btob/website_configuration/company_active 1
56+
* @magentoConfigFixture default_store company/general/allow_company_registration 1
5557
* @dataProvider queryDataProvider
5658
* @param string $query
5759
* @param array $variables
60+
* @param array $variables2 This is the second set of variables to be used in the second request
5861
* @param string $operationName
5962
* @param string $expected
6063
* @return void
6164
* @throws \Exception
6265
*/
63-
public function testState(string $query, array $variables, string $operationName, string $expected): void
66+
public function testState(string $query, array $variables, array $variables2, string $operationName, string $expected): void
6467
{
6568
$jsonEncodedRequest = json_encode([
6669
'query' => $query,
@@ -69,9 +72,15 @@ public function testState(string $query, array $variables, string $operationName
6972
]);
7073
$output1 = $this->request($jsonEncodedRequest, $operationName, true);
7174
$this->assertStringContainsString($expected, $output1);
75+
if ($variables2) {
76+
$jsonEncodedRequest = json_encode([
77+
'query' => $query,
78+
'variables' => $variables2,
79+
'operationName' => $operationName
80+
]);
81+
}
7282
$output2 = $this->request($jsonEncodedRequest, $operationName);
7383
$this->assertStringContainsString($expected, $output2);
74-
$this->assertEquals($output1, $output2);
7584
}
7685

7786
/**
@@ -160,6 +169,7 @@ public function queryDataProvider(): array
160169
}
161170
QUERY,
162171
['id' => 4],
172+
[],
163173
'navigationMenu',
164174
'"id":4,"name":"Category 1.1","product_count":2,'
165175
],
@@ -209,6 +219,7 @@ public function queryDataProvider(): array
209219
}
210220
QUERY,
211221
['name' => 'Configurable%20Product', 'onServer' => false],
222+
[],
212223
'productDetailByName',
213224
'"sku":"configurable","name":"Configurable Product"'
214225
],
@@ -257,6 +268,7 @@ public function queryDataProvider(): array
257268
}
258269
QUERY,
259270
['id' => 4, 'currentPage' => 1, 'pageSize' => 12],
271+
[],
260272
'category',
261273
'"url_key":"category-1-1","name":"Category 1.1"'
262274
],
@@ -320,6 +332,7 @@ public function queryDataProvider(): array
320332
}
321333
QUERY,
322334
['name' => 'Simple Product1', 'onServer' => false],
335+
[],
323336
'productDetail',
324337
'"sku":"simple1","name":"Simple Product1"'
325338
],
@@ -333,9 +346,10 @@ public function queryDataProvider(): array
333346
}
334347
QUERY,
335348
['urlKey' => 'no-route'],
349+
[],
336350
'resolveUrl',
337351
'"type":"CMS_PAGE","id":1'
338-
],
352+
]
339353
];
340354
}
341355
}

dev/tests/integration/testsuite/Magento/GraphQl/App/State/Collector.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ private function cloneArray(array $array) : array
3838
return array_map(
3939
function ($element) {
4040
if (is_object($element)) {
41-
return clone $element;
41+
$reflectionElement = new \ReflectionObject($element);
42+
if ($reflectionElement->isCloneable()) {
43+
return clone $element;
44+
}
4245
}
4346
if (is_array($element)) {
4447
return $this->cloneArray($element);
@@ -88,14 +91,20 @@ public function getPropertiesFromObject(object $object, $doClone = false, &$didC
8891
foreach ($objReflection->getProperties() as $property) {
8992
$propName = $property->getName();
9093
$property->setAccessible(true);
94+
if (!$property->isInitialized($object)) {
95+
continue;
96+
}
9197
$value = $property->getValue($object);
9298
if (!$doClone) {
9399
$properties[$propName] = $value;
94100
continue;
95101
}
96102
if (is_object($value)) {
97-
$didClone = true;
98-
$properties[$propName] = clone $value;
103+
$reflectionValue = new \ReflectionObject($value);
104+
if ($reflectionValue->isCloneable()) {
105+
$didClone = true;
106+
$properties[$propName] = clone $value;
107+
}
99108
} elseif (is_array($value)) {
100109
$didClone = true;
101110
$properties[$propName] = $this->cloneArray($value);

0 commit comments

Comments
 (0)