Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateDefaultSourceItemAtProductSaveTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 use PHPUnit\Framework\TestCase;
14 
16 {
20  private $productRepository;
21 
25  private $getDefaultSourceItemBySku;
26 
27  protected function setUp()
28  {
29  parent::setUp();
30 
31  $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
32  $this->getDefaultSourceItemBySku = Bootstrap::getObjectManager()->get(GetDefaultSourceItemBySku::class);
33  }
34 
42  {
43  // SKU-3 is out of stock
44  $product = $this->productRepository->get('SKU-3');
45  $this->productRepository->save($product);
46 
47  $defaultSourceItem = $this->getDefaultSourceItemBySku->execute('SKU-3');
48  self::assertNull(
49  $defaultSourceItem,
50  'Default source was accidentally created on a product not assigned while saving it'
51  );
52  }
53 }