Skip to content

Commit

Permalink
Merge branch '2.3-develop' into 714
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaKis committed Mar 26, 2018
2 parents d0dd2e7 + 3b5a20b commit 15cffa4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function aroundCheckQuoteItemQty(
$result = $this->objectFactory->create();
$result->setHasError(false);

$qty = $this->getNumber($qtyToCheck);
$qty = $this->getNumber($itemQty);

$skus = $this->getSkusByProductIds->execute([$productId]);
$productSku = $skus[$productId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\CartItemInterface;
use Magento\Quote\Api\Data\CartItemInterfaceFactory;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use PHPUnit\Framework\TestCase;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface;
use Magento\InventoryReservations\Model\CleanupReservationsInterface;
use Magento\InventoryReservations\Model\ReservationBuilderInterface;
use Magento\InventoryReservationsApi\Api\AppendReservationsInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PlaceOrderOnDefaultSourceTest extends TestCase
class PlaceOrderOnDefaultStockTest extends TestCase
{
/**
* @var DefaultStockProviderInterface
Expand Down Expand Up @@ -63,16 +62,6 @@ class PlaceOrderOnDefaultSourceTest extends TestCase
*/
private $cartItemFactory;

/**
* @var AppendReservationsInterface
*/
private $appendReservations;

/**
* @var ReservationBuilderInterface
*/
private $reservationBuilder;

/**
* @var SearchCriteriaBuilder
*/
Expand All @@ -88,6 +77,11 @@ class PlaceOrderOnDefaultSourceTest extends TestCase
*/
private $registry;

/**
* @var OrderManagementInterface
*/
private $orderManagement;

protected function setUp()
{
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
Expand All @@ -98,9 +92,8 @@ protected function setUp()
$this->cartItemFactory = Bootstrap::getObjectManager()->get(CartItemInterfaceFactory::class);
$this->defaultStockProvider = Bootstrap::getObjectManager()->get(DefaultStockProviderInterface::class);
$this->cleanupReservations = Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class);
$this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class);
$this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class);
$this->orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
$this->orderManagement = Bootstrap::getObjectManager()->get(OrderManagementInterface::class);
}

/**
Expand All @@ -115,12 +108,8 @@ protected function setUp()
*/
public function testPlaceOrderWithInStockProduct()
{
$this->markTestSkipped(
'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687'
);
$sku = 'SKU-1';
$quoteItemQty = 3.8;
$reservedDuringCheckoutQty = 1.5;

$cart = $this->getCart();
$product = $this->productRepository->get($sku);
Expand All @@ -139,14 +128,11 @@ public function testPlaceOrderWithInStockProduct()
$cart->addItem($cartItem);
$this->cartRepository->save($cart);

$this->appendReservation($sku, -$reservedDuringCheckoutQty);

$orderId = $this->cartManagement->placeOrder($cart->getId());

self::assertNotNull($orderId);

//cleanup
$this->appendReservation($sku, $reservedDuringCheckoutQty);
$this->deleteOrderById((int)$orderId);
}

Expand All @@ -162,12 +148,8 @@ public function testPlaceOrderWithInStockProduct()
*/
public function testPlaceOrderWithOutOffStockProduct()
{
$this->markTestSkipped(
'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687'
);
$sku = 'SKU-1';
$quoteItemQty = 5.5;
$reservedDuringCheckoutQty = 4.9;
$quoteItemQty = 8.7;

$cart = $this->getCart();
$product = $this->productRepository->get($sku);
Expand All @@ -186,33 +168,10 @@ public function testPlaceOrderWithOutOffStockProduct()
$cart->addItem($cartItem);
$this->cartRepository->save($cart);

//append reservation during checkout to make laking quantity in stock
$this->appendReservation($sku, -$reservedDuringCheckoutQty);

self::expectException(LocalizedException::class);
$orderId = $this->cartManagement->placeOrder($cart->getId());

self::assertNull($orderId);

//cleanup
$this->appendReservation($sku, $reservedDuringCheckoutQty);
}

/**
* @param string $productSku
* @param float $qty
* @return void
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Validation\ValidationException
*/
private function appendReservation(string $productSku, float $qty)
{
$this->appendReservations->execute([
$this->reservationBuilder->setStockId(
$this->defaultStockProvider->getId()
)->setSku($productSku)->setQuantity($qty)->build(),
]);
}

/**
Expand All @@ -238,6 +197,7 @@ private function deleteOrderById(int $orderId)
{
$this->registry->unregister('isSecureArea');
$this->registry->register('isSecureArea', true);
$this->orderManagement->cancel($orderId);
$this->orderRepository->delete($this->orderRepository->get($orderId));
$this->registry->unregister('isSecureArea');
$this->registry->register('isSecureArea', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\Data\CartItemInterface;
use Magento\Quote\Api\Data\CartItemInterfaceFactory;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\TestCase;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\InventoryReservations\Model\CleanupReservationsInterface;
use Magento\InventoryReservations\Model\ReservationBuilderInterface;
use Magento\InventoryReservationsApi\Api\AppendReservationsInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\InventoryApi\Api\StockRepositoryInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PlaceOrderOnNotDefaultSourceTest extends TestCase
class PlaceOrderOnNotDefaultStockTest extends TestCase
{
/**
* @var CleanupReservationsInterface
Expand All @@ -62,16 +62,6 @@ class PlaceOrderOnNotDefaultSourceTest extends TestCase
*/
private $cartItemFactory;

/**
* @var AppendReservationsInterface
*/
private $appendReservations;

/**
* @var ReservationBuilderInterface
*/
private $reservationBuilder;

/**
* @var StockRepositoryInterface
*/
Expand All @@ -97,20 +87,30 @@ class PlaceOrderOnNotDefaultSourceTest extends TestCase
*/
private $registry;

/**
* @var OrderManagementInterface
*/
private $orderManagement;

/**
* @var StoreManagerInterface
*/
private $storeManager;

protected function setUp()
{
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
$this->stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class);
$this->storeRepository = Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class);
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
$this->cartManagement = Bootstrap::getObjectManager()->get(CartManagementInterface::class);
$this->cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class);
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
$this->cartItemFactory = Bootstrap::getObjectManager()->get(CartItemInterfaceFactory::class);
$this->cleanupReservations = Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class);
$this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class);
$this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class);
$this->orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
$this->orderManagement = Bootstrap::getObjectManager()->get(OrderManagementInterface::class);
}

/**
Expand All @@ -130,13 +130,9 @@ protected function setUp()
*/
public function testPlaceOrderWithInStockProduct()
{
$this->markTestSkipped(
'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687'
);
$sku = 'SKU-1';
$stockId = 10;
$quoteItemQty = 4;
$reservedDuringCheckoutQty = 1.5;
$sku = 'SKU-2';
$stockId = 30;
$quoteItemQty = 2.2;

$cart = $this->getCartByStockId($stockId);
$product = $this->productRepository->get($sku);
Expand All @@ -154,15 +150,10 @@ public function testPlaceOrderWithInStockProduct()
);
$cart->addItem($cartItem);
$this->cartRepository->save($cart);

$this->appendReservation($sku, -$reservedDuringCheckoutQty, $stockId);

$orderId = $this->cartManagement->placeOrder($cart->getId());

self::assertNotNull($orderId);

//cleanup
$this->appendReservation($sku, $reservedDuringCheckoutQty, $stockId);
$this->deleteOrderById((int)$orderId);
}

Expand All @@ -183,13 +174,9 @@ public function testPlaceOrderWithInStockProduct()
*/
public function testPlaceOrderWithOutOffStockProduct()
{
$this->markTestSkipped(
'Fix Integration Test for placing Order https://github.com/magento-engcom/msi/issues/687'
);
$sku = 'SKU-1';
$stockId = 10;
$quoteItemQty = 4;
$reservedDuringCheckoutQty = 3.8;
$sku = 'SKU-2';
$stockId = 30;
$quoteItemQty = 6.2;

$cart = $this->getCartByStockId($stockId);
$product = $this->productRepository->get($sku);
Expand All @@ -208,32 +195,10 @@ public function testPlaceOrderWithOutOffStockProduct()
$cart->addItem($cartItem);
$this->cartRepository->save($cart);

//append reservation during checkout to make laking quantity in stock
$this->appendReservation($sku, -$reservedDuringCheckoutQty, $stockId);

self::expectException(LocalizedException::class);
$orderId = $this->cartManagement->placeOrder($cart->getId());

self::assertNull($orderId);

//cleanup
$this->appendReservation($sku, $reservedDuringCheckoutQty, $stockId);
}

/**
* @param string $productSku
* @param float $qty
* @param int $stockId
* @return void
* @throws CouldNotSaveException
* @throws InputException
* @throws ValidationException
*/
private function appendReservation(string $productSku, float $qty, int $stockId)
{
$this->appendReservations->execute([
$this->reservationBuilder->setStockId($stockId)->setSku($productSku)->setQuantity($qty)->build(),
]);
}

/**
Expand Down Expand Up @@ -261,6 +226,7 @@ private function getCartByStockId(int $stockId): CartInterface
}
/** @var StoreInterface $store */
$store = $this->storeRepository->get($storeCode);
$this->storeManager->setCurrentStore($storeCode);
$cart->setStoreId($store->getId());

return $cart;
Expand All @@ -273,6 +239,7 @@ private function deleteOrderById(int $orderId)
{
$this->registry->unregister('isSecureArea');
$this->registry->register('isSecureArea', true);
$this->orderManagement->cancel($orderId);
$this->orderRepository->delete($this->orderRepository->get($orderId));
$this->registry->unregister('isSecureArea');
$this->registry->register('isSecureArea', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected function setUp()

public function testRouteConfigsValidation()
{
$this->markTestSkipped('https://github.com/magento-engcom/msi/issues/657');
$invalidFiles = [];

$componentRegistrar = new ComponentRegistrar();
Expand Down
5 changes: 4 additions & 1 deletion lib/internal/Magento/Framework/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ protected function _getMatchedNode($nodePath)
$node = null;
if ($matchedNodes->length > 1) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase("More than one node matching the query: %1", [$nodePath])
new \Magento\Framework\Phrase(
"More than one node matching the query: %1, Xml is: %2",
[$nodePath, $this->dom->saveXML()]
)
);
} elseif ($matchedNodes->length == 1) {
$node = $matchedNodes->item(0);
Expand Down

0 comments on commit 15cffa4

Please sign in to comment.