|
| 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\InventoryImportExport\Test\Unit\Model\Import; |
| 9 | + |
| 10 | +use Magento\InventoryImportExport\Model\Import\SourceItemConvert; |
| 11 | +use Magento\InventoryImportExport\Model\Import\Sources; |
| 12 | +use Magento\InventoryApi\Api\Data\SourceItemInterface; |
| 13 | +use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory; |
| 14 | +use PHPUnit\Framework\MockObject\MockObject; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +class SourceItemConvertTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var SourceItemConvert |
| 21 | + */ |
| 22 | + private $model; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var SourceItemInterface|MockObject |
| 26 | + */ |
| 27 | + private $sourceItem; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var SourceItemInterfaceFactory|MockObject |
| 31 | + */ |
| 32 | + private $sourceItemFactory; |
| 33 | + |
| 34 | + /** |
| 35 | + * @inheritdoc |
| 36 | + */ |
| 37 | + protected function setUp(): void |
| 38 | + { |
| 39 | + $this->sourceItemFactory = $this->createMock(SourceItemInterfaceFactory::class); |
| 40 | + $this->sourceItem = $this->getMockBuilder(SourceItemInterface::class) |
| 41 | + ->getMock(); |
| 42 | + $this->sourceItemFactory->expects($this->any()) |
| 43 | + ->method('create') |
| 44 | + ->willReturn($this->sourceItem); |
| 45 | + $this->model = new SourceItemConvert($this->sourceItemFactory); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param array $bunch |
| 50 | + * @param int $expectedStatus |
| 51 | + * |
| 52 | + * @return void |
| 53 | + * @dataProvider dataProviderConvert |
| 54 | + */ |
| 55 | + public function testConvert(array $bunch, int $expectedStatus) : void |
| 56 | + { |
| 57 | + $this->sourceItem->expects($this->once()) |
| 58 | + ->method('setStatus') |
| 59 | + ->with($expectedStatus); |
| 60 | + $this->model->convert($bunch); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Data provider for callbackValidateProduct test. |
| 65 | + * |
| 66 | + * @return array |
| 67 | + */ |
| 68 | + public function dataProviderConvert(): array |
| 69 | + { |
| 70 | + return [ |
| 71 | + [ |
| 72 | + [ |
| 73 | + [ |
| 74 | + Sources::COL_SOURCE_CODE => 'default', |
| 75 | + Sources::COL_SKU => 'test', |
| 76 | + Sources::COL_QTY => -10 |
| 77 | + ], |
| 78 | + ], |
| 79 | + 1 |
| 80 | + ], |
| 81 | + [ |
| 82 | + [ |
| 83 | + [ |
| 84 | + Sources::COL_SOURCE_CODE => 'default', |
| 85 | + Sources::COL_SKU => 'test', |
| 86 | + Sources::COL_QTY => 0 |
| 87 | + ], |
| 88 | + ], |
| 89 | + 1 |
| 90 | + ], |
| 91 | + [ |
| 92 | + [ |
| 93 | + [ |
| 94 | + Sources::COL_SOURCE_CODE => 'default', |
| 95 | + Sources::COL_SKU => 'test', |
| 96 | + Sources::COL_QTY => 10 |
| 97 | + ], |
| 98 | + ], |
| 99 | + 1 |
| 100 | + ], |
| 101 | + [ |
| 102 | + [ |
| 103 | + [ |
| 104 | + Sources::COL_SOURCE_CODE => 'default', |
| 105 | + Sources::COL_SKU => 'test', |
| 106 | + Sources::COL_QTY => -10, |
| 107 | + Sources::COL_STATUS => 1 |
| 108 | + ], |
| 109 | + ], |
| 110 | + 1 |
| 111 | + ], |
| 112 | + [ |
| 113 | + [ |
| 114 | + [ |
| 115 | + Sources::COL_SOURCE_CODE => 'default', |
| 116 | + Sources::COL_SKU => 'test', |
| 117 | + Sources::COL_QTY => 10, |
| 118 | + Sources::COL_STATUS => 0 |
| 119 | + ], |
| 120 | + ], |
| 121 | + 0 |
| 122 | + ], |
| 123 | + ]; |
| 124 | + } |
| 125 | +} |
0 commit comments