Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegisterProductsSaleTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 use PHPUnit\Framework\TestCase;
18 
19 class RegisterProductsSaleTest extends TestCase
20 {
24  private $getProductSalableQty;
25 
29  private $productRepository;
30 
34  private $websiteRepository;
35 
39  private $stockManagement;
40 
44  private $defaultStockProvider;
45 
49  private $isProductSalable;
50 
54  protected function setUp()
55  {
56  $this->getProductSalableQty = Bootstrap::getObjectManager()->get(GetProductSalableQtyInterface::class);
57  $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
58  $this->websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class);
59  $this->stockManagement = Bootstrap::getObjectManager()->get(StockManagement::class);
60  $this->defaultStockProvider = Bootstrap::getObjectManager()->get(DefaultStockProviderInterface::class);
61  $this->isProductSalable = Bootstrap::getObjectManager()->get(IsProductSalableInterface::class);
62  }
63 
71  public function testRegisterProductsSale()
72  {
73  self::assertEquals(
74  22,
75  $this->getProductSalableQty->execute('simple', $this->defaultStockProvider->getId())
76  );
77  self::assertEquals(
78  24,
79  $this->getProductSalableQty->execute('custom-design-simple-product', $this->defaultStockProvider->getId())
80  );
81  $bundleProduct = $this->productRepository->get('bundle-product');
82  $bundleOptionProduct1 = $this->productRepository->get('simple');
83  $bundleOptionProduct2 = $this->productRepository->get('custom-design-simple-product');
84  $website = $this->websiteRepository->get('base');
85  $this->stockManagement->registerProductsSale(
86  [
87  $bundleProduct->getId() => 1,
88  $bundleOptionProduct1->getId() => 10,
89  $bundleOptionProduct2->getId() => 10,
90 
91  ],
92  $website->getId()
93  );
94  self::assertEquals(
95  22,
96  $this->getProductSalableQty->execute('simple', $this->defaultStockProvider->getId())
97  );
98  self::assertEquals(
99  24,
100  $this->getProductSalableQty->execute('custom-design-simple-product', $this->defaultStockProvider->getId())
101  );
102  }
103 }
$bundleProduct