From 1d43cca11d529da8184a30a307cd0fc4039350f9 Mon Sep 17 00:00:00 2001 From: jekabs Date: Mon, 17 Aug 2020 15:57:55 +0300 Subject: [PATCH 1/3] compare_arrays_recursively_fix -Removed compare arrays recursively from WebApiAbstract and added it in a separate method --- .../Helper/CompareArraysRecursively.php | 70 +++++++++++++++++++ .../TestFramework/TestCase/WebapiAbstract.php | 56 --------------- .../AbstractProductExportTestHelper.php | 9 ++- .../BundleProductMultipleOptionsTest.php | 18 ++++- 4 files changed, 95 insertions(+), 58 deletions(-) create mode 100644 dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php b/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php new file mode 100644 index 000000000..d8a88c721 --- /dev/null +++ b/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php @@ -0,0 +1,70 @@ + [ + * 'items' => [ + * [ + * 'sku' => 'bundle-product', + * 'type_id' => 'bundle', + * 'items' => [ + * [ + * 'title' => 'Bundle Product Items', + * 'sku' => 'bundle-product', + * 'options' => [ + * [ + * 'price' => 2.75, + * 'label' => 'Simple Product', + * 'product' => [ + * 'name' => 'Simple Product', + * 'sku' => 'simple', + * ] + * ] + * ] + * ] + * ]; + * ``` + * + * @param array $expected + * @param array $actual + * @return array + */ + public function execute(array $expected, array $actual): array + { + $diffResult = []; + + foreach ($expected as $key => $value) { + if (array_key_exists($key, $actual)) { + if (is_array($value)) { + $recursiveDiff = $this->execute($value, $actual[$key]); + if (!empty($recursiveDiff)) { + $diffResult[$key] = $recursiveDiff; + } + } else { + if (!in_array($value, $actual, true)) { + $diffResult[$key] = $value; + } + } + } else { + $diffResult[$key] = $value; + } + } + + return $diffResult; + } +} diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php index 91be839aa..7ccab097d 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php @@ -766,60 +766,4 @@ protected function assertWebApiCallErrors(array $serviceInfo, array $data, array } } } - - /** - * Compare arrays recursively regardless of nesting. - * Can compare arrays that have both one level and n-level nesting. - * ``` - * [ - * 'products' => [ - * 'items' => [ - * [ - * 'sku' => 'bundle-product', - * 'type_id' => 'bundle', - * 'items' => [ - * [ - * 'title' => 'Bundle Product Items', - * 'sku' => 'bundle-product', - * 'options' => [ - * [ - * 'price' => 2.75, - * 'label' => 'Simple Product', - * 'product' => [ - * 'name' => 'Simple Product', - * 'sku' => 'simple', - * ] - * ] - * ] - * ] - * ]; - * ``` - * - * @param array $expected - * @param array $actual - * @return array - */ - public function compareArraysRecursively(array $expected, array $actual): array - { - $diffResult = []; - - foreach ($expected as $key => $value) { - if (array_key_exists($key, $actual)) { - if (is_array($value)) { - $recursiveDiff = $this->compareArraysRecursively($value, $actual[$key]); - if (!empty($recursiveDiff)) { - $diffResult[$key] = $recursiveDiff; - } - } else { - if (!in_array($value, $actual, true)) { - $diffResult[$key] = $value; - } - } - } else { - $diffResult[$key] = $value; - } - } - - return $diffResult; - } } diff --git a/dev/tests/api-functional/testsuite/Magento/CatalogExport/AbstractProductExportTestHelper.php b/dev/tests/api-functional/testsuite/Magento/CatalogExport/AbstractProductExportTestHelper.php index bb5e17ced..e277c8b0d 100644 --- a/dev/tests/api-functional/testsuite/Magento/CatalogExport/AbstractProductExportTestHelper.php +++ b/dev/tests/api-functional/testsuite/Magento/CatalogExport/AbstractProductExportTestHelper.php @@ -14,6 +14,7 @@ use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\WebapiAbstract; +use Magento\TestFramework\Helper\CompareArraysRecursively; /** * Class AbstractProductExportTestHelper @@ -32,6 +33,11 @@ abstract class AbstractProductExportTestHelper extends WebapiAbstract */ private $objectManager; + /** + * @var CompareArraysRecursively + */ + private $compareArraysRecursively; + /** * @var Products */ @@ -62,6 +68,7 @@ protected function setUp(): void $this->productsFeed = $this->objectManager->get(Products::class); $this->indexer = Bootstrap::getObjectManager()->create(Indexer::class); $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); + $this->compareArraysRecursively = $this->objectManager->create(CompareArraysRecursively::class); $this->createServiceInfo = [ 'rest' => [ @@ -94,7 +101,7 @@ protected function assertProductsEquals(array $expected, array $actual): void } } - $diff = $this->compareArraysRecursively( + $diff = $this->compareArraysRecursively->execute( $this->camelToSnakeCaseRecursive($expected), $actual ); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php index 3409b5e3a..6b095f639 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php @@ -8,12 +8,28 @@ namespace Magento\GraphQl\Bundle; use Magento\TestFramework\TestCase\GraphQlAbstract; +use Magento\TestFramework\Helper\Bootstrap; +use \Magento\TestFramework\Helper\CompareArraysRecursively; /** * Bundle product with multiple options test. */ class BundleProductMultipleOptionsTest extends GraphQlAbstract { + /** + * @var CompareArraysRecursively + */ + private $compareArraysRecursively; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $objectManager = Bootstrap::getObjectManager(); + $this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class); + } + /** * @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options.php * @param array $bundleProductDataProvider @@ -85,7 +101,7 @@ private function assertBundleProduct(array $response, array $bundleProductDataPr $productItems = $response['products']['items']; foreach ($bundleProductDataProvider as $key => $data) { - $diff = $this->compareArraysRecursively($data, $productItems[$key]); + $diff = $this->compareArraysRecursively->execute($data, $productItems[$key]); self::assertEquals([], $diff, "Actual response doesn't equal to expected data"); } } From e1414fecc0dc4db93a7c6444d57cdce610284a3e Mon Sep 17 00:00:00 2001 From: jekabs Date: Mon, 17 Aug 2020 16:04:40 +0300 Subject: [PATCH 2/3] compare_arrays_recursively_fix --- .../Helper/CompareArraysRecursively.php | 1 + .../TestFramework/TestCase/WebapiAbstract.php | 769 ------------------ 2 files changed, 1 insertion(+), 769 deletions(-) delete mode 100644 dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php b/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php index d8a88c721..c49a6dcd4 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php @@ -9,6 +9,7 @@ /** * Class for comparing arrays recursively + * TODO: This override can be removed once the same code is merged in magento core. */ class CompareArraysRecursively { diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php deleted file mode 100644 index 7ccab097d..000000000 --- a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php +++ /dev/null @@ -1,769 +0,0 @@ - \Magento\TestFramework\TestCase\Webapi\Adapter\Soap::class, - self::ADAPTER_REST => \Magento\TestFramework\TestCase\Webapi\Adapter\Rest::class, - ]; - - /** - * Initialize fixture namespaces. - * //phpcs:disable - */ - public static function setUpBeforeClass(): void - { - //phpcs:enable - parent::setUpBeforeClass(); - self::_setFixtureNamespace(); - } - - /** - * Run garbage collector for cleaning memory - * - * @return void - * //phpcs:disable - */ - public static function tearDownAfterClass(): void - { - //phpcs:enable - //clear garbage in memory - gc_collect_cycles(); - - $fixtureNamespace = self::_getFixtureNamespace(); - if (isset(self::$_classLevelFixtures[$fixtureNamespace]) - && count(self::$_classLevelFixtures[$fixtureNamespace]) - ) { - self::_deleteFixtures(self::$_classLevelFixtures[$fixtureNamespace]); - } - - //ever disable secure area on class down - self::_enableSecureArea(false); - self::_unsetFixtureNamespace(); - parent::tearDownAfterClass(); - } - - /** - * Call safe delete for models which added to delete list, Restore config values changed during the test - * - * @return void - */ - protected function tearDown(): void - { - $fixtureNamespace = self::_getFixtureNamespace(); - if (isset(self::$_methodLevelFixtures[$fixtureNamespace]) - && count(self::$_methodLevelFixtures[$fixtureNamespace]) - ) { - self::_deleteFixtures(self::$_methodLevelFixtures[$fixtureNamespace]); - } - $this->_callModelsDelete(); - $this->_restoreAppConfig(); - parent::tearDown(); - } - - /** - * Perform Web API call to the system under test. - * - * @see \Magento\TestFramework\TestCase\Webapi\AdapterInterface::call() - * @param array $serviceInfo - * @param array $arguments - * @param string|null $webApiAdapterCode - * @param string|null $storeCode - * @param \Magento\Integration\Model\Integration|null $integration - * @return array|int|string|float|bool Web API call results - */ - protected function _webApiCall( - $serviceInfo, - $arguments = [], - $webApiAdapterCode = null, - $storeCode = null, - $integration = null - ) { - if ($webApiAdapterCode === null) { - /** Default adapter code is defined in PHPUnit configuration */ - $webApiAdapterCode = strtolower(TESTS_WEB_API_ADAPTER); - } - return $this->_getWebApiAdapter($webApiAdapterCode)->call($serviceInfo, $arguments, $storeCode, $integration); - } - - /** - * Mark test to be executed for SOAP adapter only. - * - * @param ?string $message - */ - protected function _markTestAsSoapOnly($message = null) - { - if (TESTS_WEB_API_ADAPTER != self::ADAPTER_SOAP) { - $this->markTestSkipped($message ? $message : "The test is intended to be executed for SOAP adapter only."); - } - } - - /** - * Mark test to be executed for REST adapter only. - * - * @param ?string $message - */ - protected function _markTestAsRestOnly($message = null) - { - if (TESTS_WEB_API_ADAPTER != self::ADAPTER_REST) { - $this->markTestSkipped($message ? $message : "The test is intended to be executed for REST adapter only."); - } - } - - /** - * Set fixture to registry - * - * @param string $key - * @param mixed $fixture - * @param int $tearDown - * @return void - * //phpcs:disable - */ - public static function setFixture($key, $fixture, $tearDown = self::AUTO_TEAR_DOWN_AFTER_METHOD) - { - //phpcs:enable - $fixturesNamespace = self::_getFixtureNamespace(); - if (!isset(self::$_fixtures[$fixturesNamespace])) { - self::$_fixtures[$fixturesNamespace] = []; - } - self::$_fixtures[$fixturesNamespace][$key] = $fixture; - if ($tearDown == self::AUTO_TEAR_DOWN_AFTER_METHOD) { - if (!isset(self::$_methodLevelFixtures[$fixturesNamespace])) { - self::$_methodLevelFixtures[$fixturesNamespace] = []; - } - self::$_methodLevelFixtures[$fixturesNamespace][] = $key; - } else { - if ($tearDown == self::AUTO_TEAR_DOWN_AFTER_CLASS) { - if (!isset(self::$_classLevelFixtures[$fixturesNamespace])) { - self::$_classLevelFixtures[$fixturesNamespace] = []; - } - self::$_classLevelFixtures[$fixturesNamespace][] = $key; - } - } - } - - /** - * Get fixture by key - * - * @param string $key - * @return mixed - * //phpcs:disable - */ - public static function getFixture($key) - { - //phpcs:enable - $fixturesNamespace = self::_getFixtureNamespace(); - if (array_key_exists($key, self::$_fixtures[$fixturesNamespace])) { - return self::$_fixtures[$fixturesNamespace][$key]; - } - return null; - } - - /** - * Call safe delete for model - * - * @param \Magento\Framework\Model\AbstractModel $model - * @param bool $secure - * @return void - * //phpcs:disable - */ - public static function callModelDelete($model, $secure = false) : void - { - //phpcs:enable - if ($model instanceof \Magento\Framework\Model\AbstractModel && $model->getId()) { - if ($secure) { - self::_enableSecureArea(); - } - $model->delete(); - if ($secure) { - self::_enableSecureArea(false); - } - } - } - - /** - * Call safe delete for model - * - * @param \Magento\Framework\Model\AbstractModel $model - * @param bool $secure - * @return \Magento\TestFramework\TestCase\WebapiAbstract - */ - public function addModelToDelete($model, $secure = false) - { - $this->_modelsToDelete[] = ['model' => $model, 'secure' => $secure]; - return $this; - } - - /** - * Get Web API adapter (create if requested one does not exist). - * - * @param string $webApiAdapterCode - * @return \Magento\TestFramework\TestCase\Webapi\AdapterInterface - * @throws \LogicException When requested Web API adapter is not declared - */ - protected function _getWebApiAdapter($webApiAdapterCode) - { - if (!isset($this->_webApiAdapters[$webApiAdapterCode])) { - if (!isset($this->_webApiAdaptersMap[$webApiAdapterCode])) { - throw new \LogicException( - sprintf('Declaration of the requested Web API adapter "%s" was not found.', $webApiAdapterCode) - ); - } - $this->_webApiAdapters[$webApiAdapterCode] = Bootstrap::getObjectManager()->get( - $this->_webApiAdaptersMap[$webApiAdapterCode] - ); - } - return $this->_webApiAdapters[$webApiAdapterCode]; - } - - /** - * Set fixtures namespace - * - * @throws \RuntimeException - * //phpcs:disable - */ - protected static function _setFixtureNamespace() - { - //phpcs:enable - if (self::$_fixturesNamespace !== null) { - throw new \RuntimeException('Fixture namespace is already set.'); - } - self::$_fixturesNamespace = uniqid(); - } - - /** - * Unset fixtures namespace - * //phpcs:disable - */ - protected static function _unsetFixtureNamespace() - { - //phpcs:enable - $fixturesNamespace = self::_getFixtureNamespace(); - unset(self::$_fixtures[$fixturesNamespace]); - self::$_fixturesNamespace = null; - } - - /** - * Get fixtures namespace - * - * @throws \RuntimeException - * @return string - * //phpcs:disable - */ - protected static function _getFixtureNamespace() - { - //phpcs:enable - - $fixtureNamespace = self::$_fixturesNamespace; - if ($fixtureNamespace === null) { - throw new \RuntimeException('Fixture namespace must be set.'); - } - return $fixtureNamespace; - } - - /** - * Enable secure/admin area - * - * @param bool $flag - * @return void - * //phpcs:disable - */ - protected static function _enableSecureArea($flag = true) - { - //phpcs:enable - - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - $objectManager->get(\Magento\Framework\Registry::class)->unregister('isSecureArea'); - if ($flag) { - $objectManager->get(\Magento\Framework\Registry::class)->register('isSecureArea', $flag); - } - } - - /** - * Call delete models from list - * - * @return \Magento\TestFramework\TestCase\WebapiAbstract - */ - protected function _callModelsDelete() - { - if ($this->_modelsToDelete) { - foreach ($this->_modelsToDelete as $key => $modelData) { - /** @var $model \Magento\Framework\Model\AbstractModel */ - $model = $modelData['model']; - $this->callModelDelete($model, $modelData['secure']); - unset($this->_modelsToDelete[$key]); - } - } - return $this; - } - - /** - * Check if all error messages are expected ones - * - * @param array $expectedMessages - * @param array $receivedMessages - */ - protected function _assertMessagesEqual($expectedMessages, $receivedMessages) - { - foreach ($receivedMessages as $message) { - $this->assertContains($message, $expectedMessages, "Unexpected message: '{$message}'"); - } - $expectedErrorsCount = count($expectedMessages); - $this->assertCount($expectedErrorsCount, $receivedMessages, 'Invalid messages quantity received'); - } - - /** - * Delete array of fixtures - * - * @param array $fixtures - * //phpcs:disable - */ - protected static function _deleteFixtures($fixtures) - { - //phpcs:enable - foreach ($fixtures as $fixture) { - self::deleteFixture($fixture, true); - } - } - - /** - * Delete fixture by key - * - * @param string $key - * @param bool $secure - * @return void - * //phpcs:disable - */ - public static function deleteFixture($key, $secure = false) - { - //phpcs:enable - $fixturesNamespace = self::_getFixtureNamespace(); - if (array_key_exists($key, self::$_fixtures[$fixturesNamespace])) { - self::callModelDelete(self::$_fixtures[$fixturesNamespace][$key], $secure); - unset(self::$_fixtures[$fixturesNamespace][$key]); - } - } - - /** TODO: Remove methods below if not used, otherwise fix them (after having some tests implemented)*/ - - /** - * Get application cache model - * - * @return \Magento\Framework\App\Cache - */ - protected function _getAppCache() - { - if (null === $this->_appCache) { - //set application path - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - /** @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ - $config = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class); - $options = $config->getOptions(); - $currentCacheDir = $options->getCacheDir(); - $currentEtcDir = $options->getEtcDir(); - /** @var Filesystem $filesystem */ - $filesystem = $objectManager->get(\Magento\Framework\Filesystem::class); - $options->setCacheDir($filesystem->getDirectoryRead(DirectoryList::CACHE)->getAbsolutePath()); - $options->setEtcDir($filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath()); - - $this->_appCache = $objectManager->get(\Magento\Framework\App\Cache::class); - - //revert paths options - $options->setCacheDir($currentCacheDir); - $options->setEtcDir($currentEtcDir); - } - return $this->_appCache; - } - - /** - * Clean config cache of application - * - * @return bool - */ - protected function _cleanAppConfigCache() - { - return $this->_getAppCache()->clean(\Magento\Framework\App\Config::CACHE_TAG); - } - - /** - * Update application config data - * - * @param string $path Config path with the form "section/group/node" - * @param string|int|null $value Value of config item - * @param bool $cleanAppCache If TRUE application cache will be refreshed - * @param bool $updateLocalConfig If TRUE local config object will be updated too - * @param bool $restore If TRUE config value will be restored after test run - * @return \Magento\TestFramework\TestCase\WebapiAbstract - * @throws \RuntimeException - */ - protected function _updateAppConfig( - $path, - $value, - $cleanAppCache = true, - $updateLocalConfig = false, - $restore = false - ) { - list($section, $group, $node) = explode('/', $path); - - if (!$section || !$group || !$node) { - throw new \RuntimeException( - sprintf('Config path must have view as "section/group/node" but now it "%s"', $path) - ); - } - - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - /** @var $config \Magento\Config\Model\Config */ - $config = $objectManager->create(\Magento\Config\Model\Config::class); - $data[$group]['fields'][$node]['value'] = $value; - $config->setSection($section)->setGroups($data)->save(); - - if ($restore && !isset($this->_origConfigValues[$path])) { - $this->_origConfigValues[$path] = (string)$objectManager->get( - \Magento\Framework\App\Config\ScopeConfigInterface::class - )->getNode( - $path, - 'default' - ); - } - - //refresh local cache - if ($cleanAppCache) { - if ($updateLocalConfig) { - $objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)->reinit(); - $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->reinitStores(); - } - - if (!$this->_cleanAppConfigCache()) { - throw new \RuntimeException('Application configuration cache cannot be cleaned.'); - } - } - - return $this; - } - - /** - * Restore config values changed during tests - */ - protected function _restoreAppConfig() - { - foreach ($this->_origConfigValues as $configPath => $origValue) { - $this->_updateAppConfig($configPath, $origValue, true, true); - } - } - - /** - * Process rest exception result. - * - * @param \Exception $e - * @return array - *
 ex.
-     * 'message' => "No such entity with %fieldName1 = %value1, %fieldName2 = %value2"
-     * 'parameters' => [
-     *      "fieldName1" => "email",
-     *      "value1" => "dummy@example.com",
-     *      "fieldName2" => "websiteId",
-     *      "value2" => 0
-     * ]
-     *
-     * 
- */ - public function processRestExceptionResult(\Exception $e) - { - $error = json_decode($e->getMessage(), true); - //Remove line breaks and replace with space - $error['message'] = trim(preg_replace('/\s+/', ' ', $error['message'])); - // remove trace and type, will only be present if server is in dev mode - unset($error['trace']); - unset($error['type']); - return $error; - } - - /** - * Verify that SOAP fault contains necessary information. - * - * @param \SoapFault $soapFault - * @param string $expectedMessage - * @param string $expectedFaultCode - * @param array $expectedErrorParams - * @param array $expectedWrappedErrors - * @param string $traceString - */ - protected function checkSoapFault( - $soapFault, - $expectedMessage, - $expectedFaultCode, - $expectedErrorParams = [], - $expectedWrappedErrors = [], - $traceString = null - ) { - $this->assertStringContainsString( - $expectedMessage, - $soapFault->getMessage(), - "Fault message is invalid." - ); - - $errorDetailsNode = 'GenericFault'; - $errorDetails = isset($soapFault->detail->$errorDetailsNode) ? $soapFault->detail->$errorDetailsNode : null; - if (!empty($expectedErrorParams) || !empty($expectedWrappedErrors)) { - /** Check SOAP fault details */ - $this->assertNotNull($errorDetails, "Details must be present."); - $this->_checkFaultParams($expectedErrorParams, $errorDetails); - $this->_checkWrappedErrors($expectedWrappedErrors, $errorDetails); - } - - if ($traceString) { - /** Check error trace */ - $traceNode = Fault::NODE_DETAIL_TRACE; - $mode = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get(\Magento\Framework\App\State::class) - ->getMode(); - if ($mode == \Magento\Framework\App\State::MODE_DEVELOPER) { - /** Developer mode changes tested behavior and it cannot properly be tested for now */ - $this->assertStringContainsString( - $traceString, - $errorDetails->$traceNode, - 'Trace Information is incorrect.' - ); - } else { - $this->assertNull($errorDetails, "Details are not expected."); - } - } - - /** Check SOAP fault code */ - $this->assertNotNull($soapFault->faultcode, "Fault code must not be empty."); - $this->assertEquals($expectedFaultCode, $soapFault->faultcode, "Fault code is invalid."); - } - - /** - * Check additional error parameters. - * - * @param array $expectedErrorParams - * @param \stdClass $errorDetails - */ - protected function _checkFaultParams($expectedErrorParams, $errorDetails) - { - $paramsNode = Fault::NODE_DETAIL_PARAMETERS; - if ($expectedErrorParams) { - $paramNode = Fault::NODE_DETAIL_PARAMETER; - $paramKey = Fault::NODE_DETAIL_PARAMETER_KEY; - $paramValue = Fault::NODE_DETAIL_PARAMETER_VALUE; - $actualParams = []; - if (isset($errorDetails->$paramsNode->$paramNode)) { - if (is_array($errorDetails->$paramsNode->$paramNode)) { - foreach ($errorDetails->$paramsNode->$paramNode as $param) { - $actualParams[$param->$paramKey] = $param->$paramValue; - } - } else { - $param = $errorDetails->$paramsNode->$paramNode; - $actualParams[$param->$paramKey] = $param->$paramValue; - } - } - $this->assertEquals( - $expectedErrorParams, - $actualParams, - "Parameters in fault details are invalid." - ); - } else { - $this->assertFalse(isset($errorDetails->$paramsNode), "Parameters are not expected in fault details."); - } - } - - /** - * Check additional wrapped errors. - * - * @param array $expectedWrappedErrors - * @param \stdClass $errorDetails - */ - protected function _checkWrappedErrors($expectedWrappedErrors, $errorDetails) - { - $wrappedErrorsNode = Fault::NODE_DETAIL_WRAPPED_ERRORS; - if ($expectedWrappedErrors) { - $wrappedErrorNode = Fault::NODE_DETAIL_WRAPPED_ERROR; - $actualWrappedErrors = []; - if (isset($errorDetails->$wrappedErrorsNode->$wrappedErrorNode)) { - $errorNode = $errorDetails->$wrappedErrorsNode->$wrappedErrorNode; - if (is_array($errorNode)) { - foreach ($errorNode as $error) { - $actualWrappedErrors[] = $this->getActualWrappedErrors($error); - } - } else { - $actualWrappedErrors[] = $this->getActualWrappedErrors($errorNode); - } - } - $this->assertEquals( - $expectedWrappedErrors, - $actualWrappedErrors, - "Wrapped errors in fault details are invalid." - ); - } else { - $this->assertFalse( - isset($errorDetails->$wrappedErrorsNode), - "Wrapped errors are not expected in fault details." - ); - } - } - - /** - * Get actual wrapped errors. - * - * @param \stdClass $errorNode - * @return array - */ - private function getActualWrappedErrors(\stdClass $errorNode) - { - if (!isset($errorNode->parameters)) { - return [ - 'message' => $errorNode->message, - ]; - } - - $actualParameters = []; - $parameterNode = $errorNode->parameters->parameter; - if (is_array($parameterNode)) { - foreach ($parameterNode as $parameter) { - $actualParameters[$parameter->key] = $parameter->value; - } - } else { - $actualParameters[$parameterNode->key] = $parameterNode->value; - } - return [ - 'message' => $errorNode->message, - // Can not rename on parameters due to Backward Compatibility - 'params' => $actualParameters, - ]; - } - - /** - * Assert webapi errors. - * - * @param array $serviceInfo - * @param array $data - * @param array $expectedErrorData - * @return void - * @throws \Exception - */ - protected function assertWebApiCallErrors(array $serviceInfo, array $data, array $expectedErrorData) - { - try { - $this->_webApiCall($serviceInfo, $data); - $this->fail('Expected throwing exception'); - } catch (\Exception $e) { - if (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) { - self::assertEquals($expectedErrorData, $this->processRestExceptionResult($e)); - self::assertEquals(WebapiException::HTTP_BAD_REQUEST, $e->getCode()); - } elseif (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) { - $this->assertInstanceOf('SoapFault', $e); - $expectedWrappedErrors = []; - foreach ($expectedErrorData['errors'] as $error) { - // @see \Magento\TestFramework\TestCase\WebapiAbstract::getActualWrappedErrors() - $expectedWrappedError = [ - 'message' => $error['message'], - ]; - if (isset($error['parameters'])) { - $expectedWrappedError['params'] = $error['parameters']; - } - $expectedWrappedErrors[] = $expectedWrappedError; - } - $this->checkSoapFault($e, $expectedErrorData['message'], 'env:Sender', [], $expectedWrappedErrors); - } else { - throw $e; - } - } - } -} From 37a35af5e16cf5e6c0c0d77a49acd992bbd7e33b Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Thu, 20 Aug 2020 16:51:23 -0500 Subject: [PATCH 3/3] remove overridden class --- .../Helper/CompareArraysRecursively.php | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php b/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php deleted file mode 100644 index c49a6dcd4..000000000 --- a/dev/tests/api-functional/framework/Magento/TestFramework/Helper/CompareArraysRecursively.php +++ /dev/null @@ -1,71 +0,0 @@ - [ - * 'items' => [ - * [ - * 'sku' => 'bundle-product', - * 'type_id' => 'bundle', - * 'items' => [ - * [ - * 'title' => 'Bundle Product Items', - * 'sku' => 'bundle-product', - * 'options' => [ - * [ - * 'price' => 2.75, - * 'label' => 'Simple Product', - * 'product' => [ - * 'name' => 'Simple Product', - * 'sku' => 'simple', - * ] - * ] - * ] - * ] - * ]; - * ``` - * - * @param array $expected - * @param array $actual - * @return array - */ - public function execute(array $expected, array $actual): array - { - $diffResult = []; - - foreach ($expected as $key => $value) { - if (array_key_exists($key, $actual)) { - if (is_array($value)) { - $recursiveDiff = $this->execute($value, $actual[$key]); - if (!empty($recursiveDiff)) { - $diffResult[$key] = $recursiveDiff; - } - } else { - if (!in_array($value, $actual, true)) { - $diffResult[$key] = $value; - } - } - } else { - $diffResult[$key] = $value; - } - } - - return $diffResult; - } -}