From e9938651eeda25bad20ffd662b785b9eace10be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szyma=C5=84ski?= Date: Fri, 29 Sep 2017 00:10:16 +0200 Subject: [PATCH 1/2] default stock install --- .../InventoryCatalog/Setup/InstallData.php | 75 +++++++++++++++++++ .../Test/Api/GetDefaultStock.php | 41 ++++++++++ 2 files changed, 116 insertions(+) create mode 100644 app/code/Magento/InventoryCatalog/Setup/InstallData.php create mode 100644 app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php diff --git a/app/code/Magento/InventoryCatalog/Setup/InstallData.php b/app/code/Magento/InventoryCatalog/Setup/InstallData.php new file mode 100644 index 000000000000..a9da44111f4c --- /dev/null +++ b/app/code/Magento/InventoryCatalog/Setup/InstallData.php @@ -0,0 +1,75 @@ +stockRepository = $stockRepository; + $this->stockFactory = $stockFactory; + $this->dataObjectHelper = $dataObjectHelper; + } + + /** + * {@inheritdoc} + */ + public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + $this->addDefaultStock(); + } + + /** + * Add default stock + * + * @return void + */ + private function addDefaultStock() + { + $data = [ + StockInterface::STOCK_ID => 1, + StockInterface::NAME => 'Default Stock' + ]; + $source = $this->stockFactory->create(); + $this->dataObjectHelper->populateWithArray($source, $data, StockInterface::class); + $this->stockRepository->save($source); + } +} diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php new file mode 100644 index 000000000000..b9c25f1aec49 --- /dev/null +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php @@ -0,0 +1,41 @@ + [ + 'resourcePath' => '/V1/inventory/stock/' . $defaultStockId, + 'httpMethod' => Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => 'inventoryApiStockRepositoryV1', + 'operation' => 'inventoryApiStockRepositoryV1Get', + ], + ]; + if (self::ADAPTER_REST == TESTS_WEB_API_ADAPTER) { + $stock = $this->_webApiCall($serviceInfo); + } else { + $stock = $this->_webApiCall($serviceInfo, ['stockId' => $defaultStockId]); + } + $this->assertEquals($defaultStockId, $stock[StockInterface::STOCK_ID]); + } +} From 18d9872d915671db29a5328cbd8c417e6e9ae575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szyma=C5=84ski?= Date: Sat, 30 Sep 2017 09:30:52 +0200 Subject: [PATCH 2/2] add suffix to test class --- app/code/Magento/InventoryCatalog/Setup/InstallData.php | 1 + .../Api/{GetDefaultStock.php => GetDefaultStockTest.php} | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) rename app/code/Magento/InventoryCatalog/Test/Api/{GetDefaultStock.php => GetDefaultStockTest.php} (88%) diff --git a/app/code/Magento/InventoryCatalog/Setup/InstallData.php b/app/code/Magento/InventoryCatalog/Setup/InstallData.php index a9da44111f4c..be52e83a20a9 100644 --- a/app/code/Magento/InventoryCatalog/Setup/InstallData.php +++ b/app/code/Magento/InventoryCatalog/Setup/InstallData.php @@ -51,6 +51,7 @@ public function __construct( /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php similarity index 88% rename from app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php rename to app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php index b9c25f1aec49..558cef20edf9 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStock.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php @@ -11,12 +11,12 @@ use Magento\Framework\Webapi\Rest\Request; /** - * Class GetDefaultStock + * Class GetDefaultStockTest */ -class GetDefaultStock extends WebapiAbstract +class GetDefaultStockTest extends WebapiAbstract { /** - * Get default stock from WebApi test + * Test that default Stock is present after installation */ public function testGetDefaultSource() {