Skip to content

Commit

Permalink
Fix set config values without configFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar65 authored and nmalevanec committed Jun 20, 2019
1 parent 875647e commit 2f2dc3e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 135 deletions.
55 changes: 34 additions & 21 deletions app/code/Magento/InventoryGraphQl/Test/Api/OnlyXLeftTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace Magento\InventoryGraphQl\Test\Api;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Config\Model\PreparedValueFactory;
use Magento\Config\Model\ResourceModel\Config\Data;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\InventoryApi\Api\StockRepositoryInterface;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
Expand All @@ -32,16 +35,26 @@ class OnlyXLeftTest extends GraphQlAbstract
protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$preparedValueFactory = $this->objectManager->get(PreparedValueFactory::class);
$resource = $this->objectManager->get(Data::class);
$value = $preparedValueFactory->create(
'cataloginventory/options/stock_threshold_qty',
101,
'default',
0
);
$resource->save($value);
$reinitableConfig = $this->objectManager->create(
ReinitableConfigInterface::class
);
$reinitableConfig->reinit();
}

/**
* Verify "Only x left" after order placement on default stock, main website.
* Verify "Only x left" default stock, main website.
*
* @magentoConfigFixture default_store cataloginventory/options/stock_threshold_qty 99
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/source_items_for_simple_on_default_source.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/create_quote_on_default_website.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/order_simple_product.php
* @magentoApiDataFixture Magento/Catalog/_files/products_new.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*/
public function testOnlyXLeftDefaultStockMainWebsite()
Expand All @@ -61,18 +74,15 @@ public function testOnlyXLeftDefaultStockMainWebsite()
$response = $this->graphQlQuery($query);

$this->assertArrayHasKey(0, $response['products']['items']);
$this->assertEquals('33', $response['products']['items'][0]['only_x_left_in_stock']);
$this->assertEquals('100', $response['products']['items'][0]['only_x_left_in_stock']);
}

/**
* Verify "Only x left" after order placement on default stock, additional website.
*
* @magentoConfigFixture store_for_eu_website_store cataloginventory/options/stock_threshold_qty 99
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/source_items_for_simple_on_default_source.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/create_quote_on_default_website.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/order_simple_product.php
* @magentoApiDataFixture Magento/Catalog/_files/products_new.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*/
public function testOnlyXLeftDefaultStockAdditionalWebsite()
Expand All @@ -94,20 +104,17 @@ public function testOnlyXLeftDefaultStockAdditionalWebsite()
$headerMap = ['Store' => 'store_for_eu_website'];
$response = $this->graphQlQuery($query, [], '', $headerMap);
$this->assertArrayHasKey(0, $response['products']['items']);
$this->assertEquals('33', $response['products']['items'][0]['only_x_left_in_stock']);
$this->assertEquals('100', $response['products']['items'][0]['only_x_left_in_stock']);
}

/**
* Verify "Only x left" after order placement on additional stock, main website.
*
* @magentoConfigFixture default_store cataloginventory/options/stock_threshold_qty 99
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
* @magentoApiDataFixture Magento/Catalog/_files/products_new.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/source_items_for_simple_on_multi_source.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/create_quote_on_default_website.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/order_simple_product.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*/
public function testOnlyXLeftAdditionalStockMainWebsite()
Expand All @@ -134,15 +141,12 @@ public function testOnlyXLeftAdditionalStockMainWebsite()
/**
* Verify "Only x left" after order placement on additional stock, additional website.
*
* @magentoConfigFixture default_store cataloginventory/options/stock_threshold_qty 99
* @magentoApiDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
* @magentoApiDataFixture Magento/Catalog/_files/products_new.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/source_items_for_simple_on_multi_source.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/create_quote_on_default_website.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryShipping/Test/_files/order_simple_product.php
* @magentoApiDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*/
public function testOnlyXLeftAdditionalStockAdditionalWebsite()
Expand Down Expand Up @@ -208,4 +212,13 @@ private function assignWebsiteToStock(int $stockId, string $websiteCode): void
$extensionAttributes->setSalesChannels($salesChannels);
$stockRepository->save($stock);
}

/**
* @inheritDoc
*/
protected function tearDown()
{
$resource = $this->objectManager->get(Data::class);
$resource->clearScopeData('default', 0);
}
}

This file was deleted.

This file was deleted.

0 comments on commit 2f2dc3e

Please sign in to comment.