Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddStockDataToCollectionTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use PHPUnit\Framework\TestCase;
15 
19 class AddStockDataToCollectionTest extends TestCase
20 {
24  private $stockStatus;
25 
29  private $storeManager;
30 
34  private $storeCodeBefore;
35 
39  protected function setUp()
40  {
41  parent::setUp();
42 
43  $this->stockStatus = Bootstrap::getObjectManager()->get(StockStatus::class);
44  $this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
45 
46  $this->storeCodeBefore = $this->storeManager->getStore()->getCode();
47  }
48 
68  public function testAddStockDataToCollection(string $store, int $expectedSize, bool $isFilterInStock)
69  {
70  $this->storeManager->setCurrentStore($store);
71 
73  $collection = Bootstrap::getObjectManager()->create(Collection::class);
74  $this->stockStatus->addStockDataToCollection($collection, $isFilterInStock);
75 
76  self::assertEquals($expectedSize, $collection->getSize());
77  }
78 
82  public function addStockDataToCollectionDataProvider(): array
83  {
84  return [
85  ['store_for_eu_website', 2, true],
86  ['store_for_us_website', 1, true],
87  ['store_for_global_website', 3, true],
88  ['store_for_eu_website', 3, false],
89  ['store_for_us_website', 1, false],
90  ['store_for_global_website', 4, false],
91  ];
92  }
93 
97  protected function tearDown()
98  {
99  if (null !== $this->storeCodeBefore) {
100  $this->storeManager->setCurrentStore($this->storeCodeBefore);
101  }
102  parent::tearDown();
103  }
104 }