Skip to content

Commit 5b51245

Browse files
committed
Merge remote-tracking branch 'origin/AC-6974-latest' into ArrowsBugFixDelivery_23112022
2 parents 914ad18 + 25defd0 commit 5b51245

File tree

2 files changed

+98
-84
lines changed

2 files changed

+98
-84
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 value 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+
* @var DeploymentConfig
40+
*/
41+
private $deploymentConfig;
42+
43+
/**
44+
* @param Random $random
45+
* @param DeploymentConfig $deploymentConfig
46+
*/
47+
public function __construct(
48+
Random $random,
49+
DeploymentConfig $deploymentConfig
50+
) {
51+
$this->random = $random;
52+
$this->deploymentConfig = $deploymentConfig;
53+
}
54+
55+
/**
56+
* @inheritDoc
57+
*/
58+
public function getOptions(): array
59+
{
60+
return [
61+
new TextConfigOption(
62+
self::INPUT_KEY_SALT,
63+
TextConfigOption::FRONTEND_WIZARD_TEXT,
64+
self::CONFIG_PATH_SALT,
65+
'GraphQl Salt'
66+
),
67+
];
68+
}
69+
70+
/**
71+
* @inheritdoc
72+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
73+
*/
74+
public function createConfig(array $data, DeploymentConfig $deploymentConfig)
75+
{
76+
$currentIdSalt = $this->deploymentConfig->get(self::CONFIG_PATH_SALT);
77+
78+
$configData = new ConfigData(ConfigFilePool::APP_ENV);
79+
80+
// Use given salt if set, else use current
81+
$id_salt = $data[self::INPUT_KEY_SALT] ?? $currentIdSalt;
82+
83+
// If there is no salt given or currently set, generate a new one
84+
$id_salt = $id_salt ?? $this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE);
85+
86+
$configData->set(self::CONFIG_PATH_SALT, $id_salt);
87+
88+
return [$configData];
89+
}
90+
91+
/**
92+
* @inheritdoc
93+
*/
94+
public function validate(array $options, DeploymentConfig $deploymentConfig)
95+
{
96+
return [];
97+
}
98+
}

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)