Skip to content

Commit

Permalink
Merge pull request #554 from magento-performance/ACPT-1388
Browse files Browse the repository at this point in the history
ACPT-1388: Add queries to GraphQlStateTest
  • Loading branch information
andimov authored Jul 28, 2023
2 parents 6da40ce + 7ea9e09 commit 0adcc13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,19 @@ protected function setUp(): void

/**
* Runs various GraphQL queries and checks if state of shared objects in Object Manager have changed
*
* @magentoConfigFixture base_website btob/website_configuration/company_active 1
* @magentoConfigFixture default_store btob/website_configuration/company_active 1
* @magentoConfigFixture default_store company/general/allow_company_registration 1
* @dataProvider queryDataProvider
* @param string $query
* @param array $variables
* @param array $variables2 This is the second set of variables to be used in the second request
* @param string $operationName
* @param string $expected
* @return void
* @throws \Exception
*/
public function testState(string $query, array $variables, string $operationName, string $expected): void
public function testState(string $query, array $variables, array $variables2, string $operationName, string $expected): void
{
$jsonEncodedRequest = json_encode([
'query' => $query,
Expand All @@ -69,9 +72,15 @@ public function testState(string $query, array $variables, string $operationName
]);
$output1 = $this->request($jsonEncodedRequest, $operationName, true);
$this->assertStringContainsString($expected, $output1);
if ($variables2) {
$jsonEncodedRequest = json_encode([
'query' => $query,
'variables' => $variables2,
'operationName' => $operationName
]);
}
$output2 = $this->request($jsonEncodedRequest, $operationName);
$this->assertStringContainsString($expected, $output2);
$this->assertEquals($output1, $output2);
}

/**
Expand Down Expand Up @@ -160,6 +169,7 @@ public function queryDataProvider(): array
}
QUERY,
['id' => 4],
[],
'navigationMenu',
'"id":4,"name":"Category 1.1","product_count":2,'
],
Expand Down Expand Up @@ -209,6 +219,7 @@ public function queryDataProvider(): array
}
QUERY,
['name' => 'Configurable%20Product', 'onServer' => false],
[],
'productDetailByName',
'"sku":"configurable","name":"Configurable Product"'
],
Expand Down Expand Up @@ -257,6 +268,7 @@ public function queryDataProvider(): array
}
QUERY,
['id' => 4, 'currentPage' => 1, 'pageSize' => 12],
[],
'category',
'"url_key":"category-1-1","name":"Category 1.1"'
],
Expand Down Expand Up @@ -320,6 +332,7 @@ public function queryDataProvider(): array
}
QUERY,
['name' => 'Simple Product1', 'onServer' => false],
[],
'productDetail',
'"sku":"simple1","name":"Simple Product1"'
],
Expand All @@ -333,9 +346,10 @@ public function queryDataProvider(): array
}
QUERY,
['urlKey' => 'no-route'],
[],
'resolveUrl',
'"type":"CMS_PAGE","id":1'
],
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ private function cloneArray(array $array) : array
return array_map(
function ($element) {
if (is_object($element)) {
return clone $element;
$reflectionElement = new \ReflectionObject($element);
if ($reflectionElement->isCloneable()) {
return clone $element;
}
}
if (is_array($element)) {
return $this->cloneArray($element);
Expand Down Expand Up @@ -88,14 +91,20 @@ public function getPropertiesFromObject(object $object, $doClone = false, &$didC
foreach ($objReflection->getProperties() as $property) {
$propName = $property->getName();
$property->setAccessible(true);
if (!$property->isInitialized($object)) {
continue;
}
$value = $property->getValue($object);
if (!$doClone) {
$properties[$propName] = $value;
continue;
}
if (is_object($value)) {
$didClone = true;
$properties[$propName] = clone $value;
$reflectionValue = new \ReflectionObject($value);
if ($reflectionValue->isCloneable()) {
$didClone = true;
$properties[$propName] = clone $value;
}
} elseif (is_array($value)) {
$didClone = true;
$properties[$propName] = $this->cloneArray($value);
Expand Down

0 comments on commit 0adcc13

Please sign in to comment.