Skip to content

Commit c0cb7d6

Browse files
author
Cody Nguyen
committed
Use function to set configuration
1 parent 4d41c25 commit c0cb7d6

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

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

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

88
namespace Magento\GraphQl\CatalogInventory;
99

10+
use Magento\Config\Model\ResourceModel\Config;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\TestFramework\ObjectManager;
1014
use Magento\TestFramework\TestCase\GraphQlAbstract;
15+
use Magento\CatalogInventory\Model\Configuration;
1116

1217
/**
1318
* Test for the product only x left in stock
1419
*/
1520
class ProductOnlyXLeftInStockTest extends GraphQlAbstract
1621
{
22+
/**
23+
* @var Config $config
24+
*/
25+
private $resourceConfig;
26+
27+
/**
28+
* @var ScopeConfigInterface
29+
*/
30+
private $scopeConfig;
31+
32+
/**
33+
* @var ReinitableConfigInterface
34+
*/
35+
private $reinitConfig;
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
protected function setUp(): void
41+
{
42+
parent::setUp();
43+
44+
$objectManager = ObjectManager::getInstance();
45+
$this->resourceConfig = $objectManager->get(Config::class);
46+
$this->scopeConfig = $objectManager->get(ScopeConfigInterface::class);
47+
$this->reinitConfig = $objectManager->get(ReinitableConfigInterface::class);
48+
}
49+
1750
/**
1851
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_all_fields.php
1952
*/
@@ -67,11 +100,17 @@ public function testQueryProductOnlyXLeftInStockEnabled()
67100
/**
68101
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock_without_categories.php
69102
* @magentoConfigFixture default_store cataloginventory/options/stock_threshold_qty 120
70-
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
71103
*/
72104
public function testQueryProductOnlyXLeftInStockOutstock()
73105
{
74106
$productSku = 'simple';
107+
$showOutOfStock = $this->scopeConfig->getValue(Configuration::XML_PATH_SHOW_OUT_OF_STOCK);
108+
109+
110+
$this->resourceConfig->saveConfig(Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
111+
1,
112+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
113+
$this->reinitConfig->reinit();
75114

76115
$query = <<<QUERY
77116
{
@@ -85,6 +124,9 @@ public function testQueryProductOnlyXLeftInStockOutstock()
85124
QUERY;
86125
$response = $this->graphQlQuery($query);
87126

127+
$this->resourceConfig->saveConfig(Configuration::XML_PATH_SHOW_OUT_OF_STOCK, $showOutOfStock);
128+
$this->reinitConfig->reinit();
129+
88130
$this->assertArrayHasKey(0, $response['products']['items']);
89131
$this->assertArrayHasKey('only_x_left_in_stock', $response['products']['items'][0]);
90132
$this->assertEquals(0, $response['products']['items'][0]['only_x_left_in_stock']);

0 commit comments

Comments
 (0)