Skip to content

Commit d8be487

Browse files
authored
Merge pull request #150 from magento-l3/L3_PR_21-10-10
L3_PR_21-10-10
2 parents 7151b60 + 8358faa commit d8be487

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

InventoryImportExport/Model/Import/SourceItemConvert.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(SourceItemInterfaceFactory $sourceItemFactory)
2727

2828
/**
2929
* Converts a data in sourceItem list.
30+
*
3031
* @param array $bunch
3132
* @return SourceItemInterface[]
3233
*/
@@ -40,9 +41,10 @@ public function convert(array $bunch): array
4041
$sourceItem->setSku($rowData[Sources::COL_SKU]);
4142
$sourceItem->setQuantity((float)$rowData[Sources::COL_QTY]);
4243

43-
$status = (int)($rowData[Sources::COL_QTY] > 0);
4444
if (isset($rowData[Sources::COL_STATUS])) {
4545
$status = (int)$rowData[Sources::COL_STATUS];
46+
} else {
47+
$status = 1;
4648
}
4749
$sourceItem->setStatus($status);
4850

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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

Comments
 (0)