@@ -38,7 +38,7 @@ class StockItemModifyCheckerTest extends TestCase
38
38
private $ stockItemModel ;
39
39
40
40
/**
41
- * @var ArrayUtils|MockObject
41
+ * @var ArrayUtils
42
42
*/
43
43
private $ arrayUtils ;
44
44
@@ -50,7 +50,7 @@ protected function setUp()
50
50
$ objectManager = new ObjectManager ($ this );
51
51
52
52
$ this ->stockItemRepository = $ this ->createPartialMock (StockItemRepository::class, ['get ' ]);
53
- $ this ->arrayUtils = $ this -> createPartialMock (ArrayUtils::class, [ ' recursiveDiff ' ] );
53
+ $ this ->arrayUtils = $ objectManager -> getObject (ArrayUtils::class);
54
54
$ this ->stockItemModel = $ this ->createPartialMock (StockItem::class, ['getId ' , 'getData ' ]);
55
55
56
56
$ this ->model = $ objectManager ->getObject (
@@ -63,33 +63,6 @@ protected function setUp()
63
63
);
64
64
}
65
65
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
-
93
66
/**
94
67
* Test for IsModified method when model is new.
95
68
*
@@ -106,27 +79,60 @@ public function testIsModifiedWhenModelIsNew(): void
106
79
/**
107
80
* Test for IsModified method when found difference between data.
108
81
*
82
+ * @param array $itemFromRepository
83
+ * @param array $model
84
+ * @param bool $expectedResult
109
85
* @return void
86
+ * @dataProvider stockItemModelDataProvider
110
87
*/
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 {
123
93
$ this ->stockItemModel ->expects ($ this ->exactly (2 ))->method ('getId ' )->willReturn ($ model ['id ' ]);
124
94
$ this ->stockItemRepository ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->stockItemModel );
125
95
$ this ->stockItemModel ->expects ($ this ->exactly (2 ))
126
96
->method ('getData ' )
127
97
->willReturnOnConsecutiveCalls ($ itemFromRepository , $ model );
128
- $ this ->arrayUtils ->expects ($ this ->once ())->method ('recursiveDiff ' )->willReturn (['qty ' => 100 ]);
129
98
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
+ ];
131
137
}
132
138
}
0 commit comments