Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions app/code/Magento/InventoryCatalog/Setup/InstallData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\InventoryCatalog\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\InventoryApi\Api\Data\StockInterfaceFactory;
use Magento\InventoryApi\Api\Data\StockInterface;
use Magento\InventoryApi\Api\StockRepositoryInterface;
use Magento\Framework\Api\DataObjectHelper;

/**
* Class InstallData
*/
class InstallData implements InstallDataInterface
{
/**
* @var StockRepositoryInterface
*/
private $stockRepository;

/**
* @var StockInterfaceFactory
*/
private $stockFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

/**
* @param StockRepositoryInterface $stockRepository
* @param StockInterfaceFactory $stockFactory
* @param DataObjectHelper $dataObjectHelper
*/
public function __construct(
StockRepositoryInterface $stockRepository,
StockInterfaceFactory $stockFactory,
DataObjectHelper $dataObjectHelper
) {
$this->stockRepository = $stockRepository;
$this->stockFactory = $stockFactory;
$this->dataObjectHelper = $dataObjectHelper;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
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);
}
}
41 changes: 41 additions & 0 deletions app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\InventoryCatalog\Test\Api;

use Magento\InventoryApi\Api\Data\StockInterface;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Framework\Webapi\Rest\Request;

/**
* Class GetDefaultStockTest
*/
class GetDefaultStockTest extends WebapiAbstract
{
/**
* Test that default Stock is present after installation
*/
public function testGetDefaultSource()
{
$defaultStockId = 1;
$serviceInfo = [
'rest' => [
'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]);
}
}