99
1010use Magento \Config \Model \ResourceModel \Config ;
1111use Magento \Framework \App \Config \ReinitableConfigInterface ;
12+ use Magento \Catalog \Api \ProductRepositoryInterface ;
1213use Magento \Framework \App \Config \ScopeConfigInterface ;
1314use Magento \TestFramework \ObjectManager ;
1415use Magento \TestFramework \TestCase \GraphQlAbstract ;
1920 */
2021class ProductOnlyXLeftInStockTest extends GraphQlAbstract
2122{
23+ /**
24+ * @var ProductRepositoryInterface
25+ */
26+ private $ productRepository ;
2227 /**
2328 * @var Config $config
2429 */
@@ -42,6 +47,7 @@ protected function setUp(): void
4247 parent ::setUp ();
4348
4449 $ objectManager = ObjectManager::getInstance ();
50+ $ this ->productRepository = $ objectManager ->create (ProductRepositoryInterface::class);
4551 $ this ->resourceConfig = $ objectManager ->get (Config::class);
4652 $ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
4753 $ this ->reinitConfig = $ objectManager ->get (ReinitableConfigInterface::class);
@@ -106,13 +112,13 @@ public function testQueryProductOnlyXLeftInStockOutstock()
106112 $ productSku = 'simple ' ;
107113 $ showOutOfStock = $ this ->scopeConfig ->getValue (Configuration::XML_PATH_SHOW_OUT_OF_STOCK );
108114
109- $ this ->resourceConfig ->saveConfig (
110- \Magento \CatalogInventory \Model \Configuration::XML_PATH_SHOW_OUT_OF_STOCK ,
111- 1 ,
112- ScopeConfigInterface::SCOPE_TYPE_DEFAULT
113- );
115+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK , 1 );
114116 $ this ->reinitConfig ->reinit ();
115117
118+ // need to resave product to reindex it with new configuration.
119+ $ product = $ this ->productRepository ->get ($ productSku );
120+ $ this ->productRepository ->save ($ product );
121+
116122 $ query = <<<QUERY
117123 {
118124 products(filter: {sku: {eq: " {$ productSku }"}})
0 commit comments