6 declare(strict_types=1);
15 use Magento\ProductAlert\Model\ResourceModel\Stock\CollectionFactory as StockCollectionFactory;
17 use PHPUnit\Framework\TestCase;
32 private $sourceItemRepository;
37 private $searchCriteriaBuilder;
42 private $sourceItemsSaveInterface;
47 private $stockCollectionFactory;
80 public function testAlertsBothSourceItemsOutOfStock()
82 $this->observer->process();
83 $stockCollection = $this->stockCollectionFactory->create();
86 foreach ($stockCollection as
$stock) {
89 $this->assertEquals(0,
$count);
111 public function testAlertsOneSourceItemInStock()
113 $this->observer->process();
114 $stockCollection = $this->stockCollectionFactory->create();
117 foreach ($stockCollection as
$stock) {
120 $this->assertEquals(0,
$count);
122 $this->changeProductIsInStock(
'eu-2', 1);
123 $this->observer->process();
125 $stockCollection = $this->stockCollectionFactory->create();
128 foreach ($stockCollection as
$stock) {
131 $this->assertEquals(1,
$count);
153 public function testAlertsBothSourceItemsInStock()
155 $this->changeProductIsInStock(
'eu-2', 1);
156 $this->changeProductIsInStock(
'default', 1);
157 $this->observer->process();
159 $stockCollection = $this->stockCollectionFactory->create();
162 foreach ($stockCollection as
$stock) {
165 $this->assertEquals(2,
$count);
174 private function changeProductIsInStock(
string $sourceCode,
int $isInStock)
188 $this->sourceItemsSaveInterface->execute([
$sourceItem]);
static getObjectManager()