|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\InventoryIndexer\Test\Unit\Plugin\InventoryApi; |
| 9 | + |
| 10 | +use Magento\InventoryApi\Api\SourceItemsSaveInterface; |
| 11 | +use Magento\InventoryApi\Api\Data\SourceItemInterface; |
| 12 | +use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface; |
| 13 | +use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemIds; |
| 14 | +use Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer; |
| 15 | +use Magento\InventoryIndexer\Plugin\InventoryApi\ReindexAfterSourceItemsSavePlugin; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +class ReindexAfterSourceItemsSavePluginTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var GetSourceItemIds|MockObject |
| 23 | + */ |
| 24 | + private $getSourceItemIds; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var SourceItemIndexer|MockObject |
| 28 | + */ |
| 29 | + private $sourceItemIndexer; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var DefaultSourceProviderInterface|MockObject |
| 33 | + */ |
| 34 | + private $defaultSourceProvider; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var SourceItemInterface|MockObject |
| 38 | + */ |
| 39 | + private $sourceItem; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var SourceItemsSaveInterface|MockObject |
| 43 | + */ |
| 44 | + private $subject; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var ReindexAfterSourceItemsSavePlugin |
| 48 | + */ |
| 49 | + private $plugin; |
| 50 | + |
| 51 | + /** |
| 52 | + * @inheridoc |
| 53 | + */ |
| 54 | + protected function setUp(): void |
| 55 | + { |
| 56 | + parent::setUp(); |
| 57 | + $this->getSourceItemIds = $this->createMock(GetSourceItemIds::class); |
| 58 | + $this->sourceItemIndexer = $this->createMock(SourceItemIndexer::class); |
| 59 | + $this->defaultSourceProvider = $this->createMock(DefaultSourceProviderInterface::class); |
| 60 | + $this->sourceItem = $this->createMock(SourceItemInterface::class); |
| 61 | + $this->subject = $this->createMock(SourceItemsSaveInterface::class); |
| 62 | + $this->plugin = new ReindexAfterSourceItemsSavePlugin( |
| 63 | + $this->getSourceItemIds, |
| 64 | + $this->sourceItemIndexer, |
| 65 | + $this->defaultSourceProvider |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + public function testAfterExecuteWithDefaultSource() : void |
| 70 | + { |
| 71 | + $defaultCode = 'default'; |
| 72 | + $this->defaultSourceProvider->expects($this->once()) |
| 73 | + ->method('getCode') |
| 74 | + ->willReturn($defaultCode); |
| 75 | + $this->sourceItem->expects($this->once()) |
| 76 | + ->method('getSourceCode') |
| 77 | + ->willReturn($defaultCode); |
| 78 | + $this->getSourceItemIds->expects($this->once()) |
| 79 | + ->method('execute') |
| 80 | + ->with([]) |
| 81 | + ->willReturn([]); |
| 82 | + $this->sourceItemIndexer->expects($this->never()) |
| 83 | + ->method('executeList'); |
| 84 | + $this->plugin->afterExecute($this->subject, null, [$this->sourceItem]); |
| 85 | + } |
| 86 | +} |
0 commit comments