Skip to content

Commit a1ac22c

Browse files
committed
MC-23633: Catalog Inventory modal refactor
1 parent 471b3f8 commit a1ac22c

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/StockItemModifyCheckerTest.php

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class StockItemModifyCheckerTest extends TestCase
3838
private $stockItemModel;
3939

4040
/**
41-
* @var ArrayUtils|MockObject
41+
* @var ArrayUtils
4242
*/
4343
private $arrayUtils;
4444

@@ -50,7 +50,7 @@ protected function setUp()
5050
$objectManager = new ObjectManager($this);
5151

5252
$this->stockItemRepository = $this->createPartialMock(StockItemRepository::class, ['get']);
53-
$this->arrayUtils = $this->createPartialMock(ArrayUtils::class, ['recursiveDiff']);
53+
$this->arrayUtils = $objectManager->getObject(ArrayUtils::class);
5454
$this->stockItemModel = $this->createPartialMock(StockItem::class, ['getId', 'getData']);
5555

5656
$this->model = $objectManager->getObject(
@@ -63,33 +63,6 @@ protected function setUp()
6363
);
6464
}
6565

66-
/**
67-
* Test for IsModified method when data is not modified.
68-
*
69-
* @return void
70-
*/
71-
public function testIsModifiedForNotModifiedModel(): void
72-
{
73-
$itemFromRepository = [
74-
'id' => 1,
75-
'low_stock_date' => '01.01.2020',
76-
'qty' => 100,
77-
];
78-
$model = [
79-
'id' => 1,
80-
'low_stock_date' => '01.01.2021',
81-
'qty' => 100
82-
];
83-
$this->stockItemModel->expects($this->exactly(2))->method('getId')->willReturn($model['id']);
84-
$this->stockItemRepository->expects($this->once())->method('get')->willReturn($this->stockItemModel);
85-
$this->stockItemModel->expects($this->exactly(2))
86-
->method('getData')
87-
->willReturnOnConsecutiveCalls($itemFromRepository, $model);
88-
$this->arrayUtils->expects($this->once())->method('recursiveDiff')->willReturn([]);
89-
90-
$this->assertFalse($this->model->isModified($this->stockItemModel));
91-
}
92-
9366
/**
9467
* Test for IsModified method when model is new.
9568
*
@@ -106,27 +79,60 @@ public function testIsModifiedWhenModelIsNew(): void
10679
/**
10780
* Test for IsModified method when found difference between data.
10881
*
82+
* @param array $itemFromRepository
83+
* @param array $model
84+
* @param bool $expectedResult
10985
* @return void
86+
* @dataProvider stockItemModelDataProvider
11087
*/
111-
public function testIsModifiedWhenDifferenceFound(): void
112-
{
113-
$itemFromRepository = [
114-
'id' => 1,
115-
'low_stock_date' => '01.01.2020',
116-
'qty' => 100,
117-
];
118-
$model = [
119-
'id' => 1,
120-
'low_stock_date' => '01.01.2021',
121-
'qty' => 99
122-
];
88+
public function testIsModified(
89+
array $itemFromRepository,
90+
array $model,
91+
bool $expectedResult
92+
): void {
12393
$this->stockItemModel->expects($this->exactly(2))->method('getId')->willReturn($model['id']);
12494
$this->stockItemRepository->expects($this->once())->method('get')->willReturn($this->stockItemModel);
12595
$this->stockItemModel->expects($this->exactly(2))
12696
->method('getData')
12797
->willReturnOnConsecutiveCalls($itemFromRepository, $model);
128-
$this->arrayUtils->expects($this->once())->method('recursiveDiff')->willReturn(['qty' => 100]);
12998

130-
$this->assertTrue($this->model->isModified($this->stockItemModel));
99+
$this->assertEquals($expectedResult, $this->model->isModified($this->stockItemModel));
100+
}
101+
102+
/**
103+
* Data provider for testIsModified.
104+
*
105+
* @return array
106+
*/
107+
public function stockItemModelDataProvider(): array
108+
{
109+
return [
110+
'Model is modified' => [
111+
'stockItemFromRepository' => [
112+
'id' => 1,
113+
'low_stock_date' => '01.01.2020',
114+
'qty' => 100,
115+
],
116+
'model' => [
117+
'id' => 1,
118+
'low_stock_date' => '01.01.2021',
119+
'qty' => 99,
120+
],
121+
'expectedResult' => true,
122+
],
123+
'Model is not modified' => [
124+
'stockItemFromRepository' => [
125+
'id' => 1,
126+
'low_stock_date' => '01.01.2020',
127+
'qty' => 100,
128+
],
129+
'model' => [
130+
'id' => 1,
131+
'low_stock_date' => '01.01.2021',
132+
'qty' => 100,
133+
],
134+
'expectedResult' => false,
135+
],
136+
];
131137
}
132138
}

0 commit comments

Comments
 (0)