Skip to content

Commit 4778bbb

Browse files
vitaliyboykonaydav
authored andcommitted
GraphQl-167: Add support for '@magentoConfigFixture' annotation on API-functional tests
1 parent 977753b commit 4778bbb

File tree

8 files changed

+144
-56
lines changed

8 files changed

+144
-56
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* Application configuration object. Used to access configuration when application is installed.
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magento\TestFramework\App;
12+
13+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\TestFramework\ObjectManager;
16+
17+
/**
18+
* @inheritdoc
19+
*/
20+
class MutableScopeConfig implements MutableScopeConfigInterface
21+
{
22+
/**
23+
* @var Config
24+
*/
25+
private $testAppConfig;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
public function isSetFlag($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
31+
{
32+
return $this->getTestAppConfig()->isSetFlag($path, $scopeType, $scopeCode);
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function getValue($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
39+
{
40+
return $this->getTestAppConfig()->getValue($path, $scopeType, $scopeCode);
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function setValue(
47+
$path,
48+
$value,
49+
$scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
50+
$scopeCode = null
51+
) {
52+
$this->persistConfig($path, $value, $scopeType, $scopeCode);
53+
return $this->getTestAppConfig()->setValue($path, $value, $scopeType, $scopeCode);
54+
}
55+
56+
/**
57+
* Clean app config cache
58+
*
59+
* @param string|null $type
60+
* @return void
61+
*/
62+
public function clean()
63+
{
64+
$this->getTestAppConfig()->clean();
65+
}
66+
67+
/**
68+
* Retrieve test app config instance
69+
*
70+
* @return \Magento\TestFramework\App\Config
71+
*/
72+
private function getTestAppConfig()
73+
{
74+
if (!$this->testAppConfig) {
75+
$this->testAppConfig = ObjectManager::getInstance()->get(ScopeConfigInterface::class);
76+
}
77+
78+
return $this->testAppConfig;
79+
}
80+
81+
/**
82+
* Persist config in database
83+
*
84+
* @param string $path
85+
* @param string $value
86+
* @param string $scopeType
87+
* @param string|null $scopeCode
88+
*/
89+
private function persistConfig($path, $value, $scopeType, $scopeCode): void
90+
{
91+
$pathParts = explode('/', $path);
92+
$store = '';
93+
if ($scopeType === \Magento\Store\Model\ScopeInterface::SCOPE_STORE) {
94+
if ($scopeCode !== null) {
95+
$store = ObjectManager::getInstance()
96+
->get(\Magento\Store\Api\StoreRepositoryInterface::class)
97+
->get($scopeCode)
98+
->getId();
99+
} else {
100+
$store = ObjectManager::getInstance()
101+
->get(\Magento\Store\Model\StoreManagerInterface::class)
102+
->getStore()
103+
->getId();
104+
}
105+
}
106+
$configData = [
107+
'section' => $pathParts[0],
108+
'website' => '',
109+
'store' => $store,
110+
'groups' => [
111+
$pathParts[1] => [
112+
'fields' => [
113+
$pathParts[2] => [
114+
'value' => $value
115+
]
116+
]
117+
]
118+
]
119+
];
120+
ObjectManager::getInstance()
121+
->get(\Magento\Config\Model\Config\Factory::class)
122+
->create(['data' => $configData])
123+
->save();
124+
}
125+
}

dev/tests/api-functional/framework/Magento/TestFramework/Bootstrap/WebapiDocBlock.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
*/
88
namespace Magento\TestFramework\Bootstrap;
99

10+
use Magento\TestFramework\Annotation\ConfigFixture;
11+
12+
/**
13+
* @inheritdoc
14+
*/
1015
class WebapiDocBlock extends \Magento\TestFramework\Bootstrap\DocBlock
1116
{
1217
/**
13-
* Get list of subscribers. In addition, register <b>magentoApiDataFixture</b> annotation processing.
18+
* Get list of subscribers.
19+
*
20+
* In addition, register magentoApiDataFixture and magentoApiConfigFixture
21+
* annotation processors
1422
*
1523
* @param \Magento\TestFramework\Application $application
1624
* @return array
@@ -19,6 +27,7 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
1927
{
2028
$subscribers = parent::_getSubscribers($application);
2129
$subscribers[] = new \Magento\TestFramework\Annotation\ApiDataFixture($this->_fixturesBaseDir);
30+
$subscribers[] = new ConfigFixture();
2231
return $subscribers;
2332
}
2433
}

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/ProductOnlyXLeftInStockTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function testQueryProductOnlyXLeftInStockDisabled()
4242
*/
4343
public function testQueryProductOnlyXLeftInStockEnabled()
4444
{
45-
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
4645
$productSku = 'simple';
4746

4847
$query = <<<QUERY

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/ProductStockStatusTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function testQueryProductStockStatusInStock()
5555
*/
5656
public function testQueryProductStockStatusOutOfStock()
5757
{
58-
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
5958
$productSku = 'simple';
6059

6160
$query = <<<QUERY

dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class ConfigFixture
3939
*/
4040
private $_storeConfigValues = [];
4141

42+
/**
43+
* @var string
44+
*/
45+
protected $annotation = 'magentoConfigFixture';
46+
4247
/**
4348
* Retrieve configuration node value
4449
*
@@ -104,10 +109,10 @@ protected function _setConfigValue($configPath, $value, $storeCode = false)
104109
protected function _assignConfigData(\PHPUnit\Framework\TestCase $test)
105110
{
106111
$annotations = $test->getAnnotations();
107-
if (!isset($annotations['method']['magentoConfigFixture'])) {
112+
if (!isset($annotations['method'][$this->annotation])) {
108113
return;
109114
}
110-
foreach ($annotations['method']['magentoConfigFixture'] as $configPathAndValue) {
115+
foreach ($annotations['method'][$this->annotation] as $configPathAndValue) {
111116
if (preg_match('/^.+?(?=_store\s)/', $configPathAndValue, $matches)) {
112117
/* Store-scoped config value */
113118
$storeCode = $matches[0] != 'current' ? $matches[0] : null;

dev/tests/integration/testsuite/Magento/SendFriend/Controller/SendmailTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class SendmailTest extends AbstractController
2626
*
2727
* @magentoDbIsolation enabled
2828
* @magentoAppIsolation enabled
29-
* @magentoDataFixture Magento/SendFriend/_files/disable_allow_guest_config.php
29+
* @magentoConfigFixture default/sendfriend/email/allow_guest 0
30+
* @magentoConfigFixture default/sendfriend/email/enabled 1
3031
* @magentoDataFixture Magento/Customer/_files/customer.php
3132
* @magentoDataFixture Magento/Catalog/_files/products.php
3233
*/

dev/tests/integration/testsuite/Magento/SendFriend/_files/disable_allow_guest_config.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/SendFriend/_files/product_simple_rollback.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)