Skip to content

Commit ac1c853

Browse files
committed
AC-6974::Cloud Native S3 Web API test Failures -2.4-develop - Fixed GraphQL testCacheIdHeaderWithCurrency Test
1 parent 528ed74 commit ac1c853

File tree

2 files changed

+100
-84
lines changed

2 files changed

+100
-84
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQlCache\Setup;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\Config\Data\ConfigData;
12+
use Magento\Framework\Config\File\ConfigFilePool;
13+
use Magento\Framework\Setup\ConfigOptionsListInterface;
14+
use Magento\Framework\Setup\Option\TextConfigOption;
15+
use Magento\Framework\Config\ConfigOptionsListConstants;
16+
use Magento\Framework\Math\Random;
17+
18+
/**
19+
* GraphQl Salt option.
20+
*/
21+
class ConfigOptionsList implements ConfigOptionsListInterface
22+
{
23+
/**
24+
* Input key for the option
25+
*/
26+
private const INPUT_KEY_SALT ='id_salt';
27+
28+
/**
29+
* Path to the values in the deployment config
30+
*/
31+
private const CONFIG_PATH_SALT = 'cache/graphql/id_salt';
32+
33+
/**
34+
* @var Random
35+
*/
36+
private $random;
37+
38+
/**
39+
* @param Random $random
40+
*/
41+
public function __construct(Random $random)
42+
{
43+
$this->random = $random;
44+
}
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
public function getOptions(): array
50+
{
51+
return [
52+
new TextConfigOption(
53+
self::INPUT_KEY_SALT,
54+
TextConfigOption::FRONTEND_WIZARD_TEXT,
55+
self::CONFIG_PATH_SALT,
56+
'GraphQl Salt'
57+
),
58+
];
59+
}
60+
61+
/**
62+
* @inheritdoc
63+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
64+
*/
65+
public function createConfig(array $data, DeploymentConfig $deploymentConfig)
66+
{
67+
$configData = new ConfigData(ConfigFilePool::APP_ENV);
68+
69+
if (!$this->isDataEmpty($data, self::INPUT_KEY_SALT)) {
70+
$salt = $this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE);
71+
$configData->set(self::CONFIG_PATH_SALT, $salt);
72+
}
73+
74+
return [$configData];
75+
}
76+
77+
/**
78+
* @inheritdoc
79+
*/
80+
public function validate(array $options, DeploymentConfig $deploymentConfig)
81+
{
82+
return [];
83+
}
84+
85+
/**
86+
* Check if data ($data) with key ($key) is empty
87+
*
88+
* @param array $data
89+
* @param string $key
90+
* @return bool
91+
*/
92+
private function isDataEmpty(array $data, $key)
93+
{
94+
if (isset($data[$key]) && $data[$key] !== '') {
95+
return false;
96+
}
97+
98+
return true;
99+
}
100+
}

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

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
*/
66
namespace Magento\TestFramework\TestCase;
77

8-
use Magento\Framework\App\DeploymentConfig\Reader;
9-
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
10-
use Magento\Framework\App\Filesystem\DirectoryList;
11-
use Magento\Framework\Config\File\ConfigFilePool;
12-
use Magento\Framework\Filesystem;
13-
use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator;
148
use Magento\TestFramework\Helper\Bootstrap;
159

1610
/**
@@ -32,26 +26,6 @@ abstract class GraphQlAbstract extends WebapiAbstract
3226
*/
3327
private $appCache;
3428

35-
/**
36-
* @var Filesystem
37-
*/
38-
private $filesystem;
39-
40-
/**
41-
* @var string
42-
*/
43-
private $envConfigPath;
44-
45-
/**
46-
* @var Reader
47-
*/
48-
private $envConfigReader;
49-
50-
/**
51-
* @var PhpFormatter
52-
*/
53-
private $formatter;
54-
5529
/**
5630
* Perform GraphQL query call via GET to the system under test.
5731
*
@@ -232,62 +206,4 @@ protected function assertResponseFields($actualResponse, $assertionMap)
232206
);
233207
}
234208
}
235-
236-
/**
237-
* If the cache id salt didn't exist in env.php before a GraphQL request it gets added. To prevent test failures
238-
* due to a config getting changed (which is normally illegal), the salt needs to be removed from env.php after
239-
* a test if it wasn't there before.
240-
*
241-
* @see \Magento\TestFramework\Isolation\DeploymentConfig
242-
*
243-
* @inheritdoc
244-
*/
245-
protected function runTest()
246-
{
247-
/** @var Reader $reader */
248-
if (!$this->envConfigPath) {
249-
/** @var ConfigFilePool $configFilePool */
250-
$configFilePool = Bootstrap::getObjectManager()->get(ConfigFilePool::class);
251-
$this->envConfigPath = $configFilePool->getPath(ConfigFilePool::APP_ENV);
252-
}
253-
$this->envConfigReader = $this->envConfigReader ?: Bootstrap::getObjectManager()->get(Reader::class);
254-
$initialConfig = $this->envConfigReader->load(ConfigFilePool::APP_ENV);
255-
256-
try {
257-
return parent::runTest();
258-
} finally {
259-
$this->formatter = $this->formatter ?: new PhpFormatter();
260-
$this->filesystem = $this->filesystem ?: Bootstrap::getObjectManager()->get(Filesystem::class);
261-
$cacheSaltPathChunks = explode('/', CacheIdCalculator::SALT_CONFIG_PATH);
262-
$currentConfig = $this->envConfigReader->load(ConfigFilePool::APP_ENV);
263-
$resetConfig = $this->resetAddedSection($initialConfig, $currentConfig, $cacheSaltPathChunks);
264-
$resetFileContents = $this->formatter->format($resetConfig);
265-
$directoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG);
266-
sleep(4);
267-
$directoryWrite->writeFile($this->envConfigPath, $resetFileContents);
268-
}
269-
}
270-
271-
/**
272-
* Go over the current deployment config and unset a section that was not present in the pre-test deployment config
273-
*
274-
* @param array $initial
275-
* @param array $current
276-
* @param string[] $chunks
277-
* @return array
278-
*/
279-
private function resetAddedSection(array $initial, array $current, array $chunks): array
280-
{
281-
if ($chunks) {
282-
$chunk = array_shift($chunks);
283-
if (!isset($initial[$chunk])) {
284-
if (isset($current[$chunk])) {
285-
unset($current[$chunk]);
286-
}
287-
} elseif (isset($current[$chunk]) && is_array($initial[$chunk]) && is_array($current[$chunk])) {
288-
$current[$chunk] = $this->resetAddedSection($initial[$chunk], $current[$chunk], $chunks);
289-
}
290-
}
291-
return $current;
292-
}
293209
}

0 commit comments

Comments
 (0)