Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddStockStatusToSelectTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use PHPUnit\Framework\TestCase;
16 
20 class AddStockStatusToSelectTest extends TestCase
21 {
25  private $stockStatus;
26 
30  private $website;
31 
35  protected function setUp()
36  {
37  parent::setUp();
38 
39  $this->stockStatus = Bootstrap::getObjectManager()->get(StockStatus::class);
40  $this->website = Bootstrap::getObjectManager()->create(Website::class);
41  }
42 
61  public function testAddStockStatusToSelect(
62  string $websiteCode,
63  int $expectedIsSalableCount,
64  int $expectedNotSalableCount
65  ) {
66  $actualIsSalableCount = $actualNotSalableCount = 0;
67 
69  $collection = Bootstrap::getObjectManager()->create(Collection::class);
70  $this->website->setCode($websiteCode);
71  $this->stockStatus->addStockStatusToSelect($collection->getSelect(), $this->website);
72 
73  foreach ($collection as $item) {
74  $item->getIsSalable() == 1 ? $actualIsSalableCount++ : $actualNotSalableCount++;
75  }
76 
77  self::assertEquals($expectedIsSalableCount, $actualIsSalableCount);
78  self::assertEquals($expectedNotSalableCount, $actualNotSalableCount);
79  self::assertEquals($expectedNotSalableCount + $expectedIsSalableCount, $collection->getSize());
80  }
81 
85  public function addStockStatusToSelectDataProvider(): array
86  {
87  return [
88  ['eu_website', 2, 3],
89  ['us_website', 1, 4],
90  ['global_website', 3, 2],
91  ];
92  }
93 
98  public function testAddStockStatusToSelectWithEmptyWebsiteCode()
99  {
101  $collection = Bootstrap::getObjectManager()->create(Collection::class);
102  $this->stockStatus->addStockStatusToSelect($collection->getSelect(), $this->website);
103  }
104 
109  public function testAddStockStatusToSelectWithNotExistedWebsiteCode()
110  {
112  $collection = Bootstrap::getObjectManager()->create(Collection::class);
113  $this->website->setCode('not_existed_code');
114  $this->stockStatus->addStockStatusToSelect($collection->getSelect(), $this->website);
115  }
116 }
if(!isset($_GET['website_code'])) $websiteCode
Definition: website.php:11