Skip to content

Commit 50404cc

Browse files
authored
Merge pull request #6089 from magento-arcticfoxes/2.4-develop-pr
MC-36959: Remove "compareArraysRecursively" logic duplication
2 parents e1c5c1d + e9493f1 commit 50404cc

File tree

2 files changed

+17
-58
lines changed

2 files changed

+17
-58
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQlAbstract.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -184,61 +184,4 @@ protected function assertResponseFields($actualResponse, $assertionMap)
184184
);
185185
}
186186
}
187-
188-
/**
189-
* Compare arrays recursively regardless of nesting.
190-
*
191-
* Can compare arrays that have both one level and n-level nesting.
192-
* ```
193-
* [
194-
* 'products' => [
195-
* 'items' => [
196-
* [
197-
* 'sku' => 'bundle-product',
198-
* 'type_id' => 'bundle',
199-
* 'items' => [
200-
* [
201-
* 'title' => 'Bundle Product Items',
202-
* 'sku' => 'bundle-product',
203-
* 'options' => [
204-
* [
205-
* 'price' => 2.75,
206-
* 'label' => 'Simple Product',
207-
* 'product' => [
208-
* 'name' => 'Simple Product',
209-
* 'sku' => 'simple',
210-
* ]
211-
* ]
212-
* ]
213-
* ]
214-
* ];
215-
* ```
216-
*
217-
* @param array $expected
218-
* @param array $actual
219-
* @return array
220-
*/
221-
public function compareArraysRecursively(array $expected, array $actual): array
222-
{
223-
$diffResult = [];
224-
225-
foreach ($expected as $key => $value) {
226-
if (array_key_exists($key, $actual)) {
227-
if (is_array($value)) {
228-
$recursiveDiff = $this->compareArraysRecursively($value, $actual[$key]);
229-
if (!empty($recursiveDiff)) {
230-
$diffResult[$key] = $recursiveDiff;
231-
}
232-
} else {
233-
if (!in_array($value, $actual, true)) {
234-
$diffResult[$key] = $value;
235-
}
236-
}
237-
} else {
238-
$diffResult[$key] = $value;
239-
}
240-
}
241-
242-
return $diffResult;
243-
}
244187
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77

88
namespace Magento\GraphQl\Bundle;
99

10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestFramework\Helper\CompareArraysRecursively;
1012
use Magento\TestFramework\TestCase\GraphQlAbstract;
1113

1214
/**
1315
* Bundle product with multiple options test.
1416
*/
1517
class BundleProductMultipleOptionsTest extends GraphQlAbstract
1618
{
19+
/**
20+
* @var CompareArraysRecursively
21+
*/
22+
private $compareArraysRecursively;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$objectManager = Bootstrap::getObjectManager();
30+
$this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class);
31+
}
32+
1733
/**
1834
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options.php
1935
* @param array $bundleProductDataProvider
@@ -85,7 +101,7 @@ private function assertBundleProduct(array $response, array $bundleProductDataPr
85101
$productItems = $response['products']['items'];
86102

87103
foreach ($bundleProductDataProvider as $key => $data) {
88-
$diff = $this->compareArraysRecursively($data, $productItems[$key]);
104+
$diff = $this->compareArraysRecursively->execute($data, $productItems[$key]);
89105
self::assertEquals([], $diff, "Actual response doesn't equal to expected data");
90106
}
91107
}

0 commit comments

Comments
 (0)