CartTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Model;
  7. use Magento\Catalog\Api\ProductRepositoryInterface;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. class CartTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var Cart
  13. */
  14. private $cart;
  15. /**
  16. * @var ProductRepositoryInterface
  17. */
  18. private $productRepository;
  19. protected function setUp()
  20. {
  21. $this->cart = Bootstrap::getObjectManager()->create(Cart::class);
  22. $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
  23. }
  24. /**
  25. * @magentoDataFixture Magento/Checkout/_files/simple_product.php
  26. * @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
  27. * @magentoDbIsolation enabled
  28. * @magentoAppIsolation enabled
  29. */
  30. public function testAddProductWithLowerQty()
  31. {
  32. $this->expectException(\Magento\Framework\Exception\LocalizedException::class);
  33. $this->expectExceptionMessage('The fewest you may purchase is 3');
  34. $product = $this->productRepository->get('simple');
  35. $this->cart->addProduct($product->getId(), ['qty' => 1]);
  36. }
  37. /**
  38. * @magentoDataFixture Magento/Checkout/_files/simple_product.php
  39. * @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
  40. * @magentoDbIsolation enabled
  41. */
  42. public function testAddProductWithNoQty()
  43. {
  44. $product = $this->productRepository->get('simple');
  45. $this->cart->addProduct($product->getId(), []);
  46. }
  47. }