13
13
use Magento \Framework \DB \Select ;
14
14
use Magento \Framework \App \ResourceConnection ;
15
15
use Magento \Catalog \Model \ResourceModel \Product \Gallery ;
16
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
17
+ use Magento \Framework \DB \Query \BatchIteratorInterface ;
16
18
17
19
class ImageTest extends \PHPUnit \Framework \TestCase
18
20
{
@@ -22,34 +24,37 @@ class ImageTest extends \PHPUnit\Framework\TestCase
22
24
protected $ objectManager ;
23
25
24
26
/**
25
- * @var AdapterInterface | \PHPUnit_Framework_MockObject_MockObject
27
+ * @var AdapterInterface | MockObject
26
28
*/
27
29
protected $ connectionMock ;
28
30
29
31
/**
30
- * @var Generator | \PHPUnit_Framework_MockObject_MockObject
32
+ * @var Generator | MockObject
31
33
*/
32
34
protected $ generatorMock ;
33
35
34
36
/**
35
- * @var ResourceConnection | \PHPUnit_Framework_MockObject_MockObject
37
+ * @var ResourceConnection | MockObject
36
38
*/
37
39
protected $ resourceMock ;
38
40
39
41
protected function setUp (): void
40
42
{
41
- $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
43
+ $ this ->objectManager =
44
+ new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
42
45
$ this ->connectionMock = $ this ->createMock (AdapterInterface::class);
43
46
$ this ->resourceMock = $ this ->createMock (ResourceConnection::class);
44
- $ this ->resourceMock ->method ('getConnection ' )->willReturn ($ this ->connectionMock );
45
- $ this ->resourceMock ->method ('getTableName ' )->willReturnArgument (0 );
47
+ $ this ->resourceMock ->method ('getConnection ' )
48
+ ->willReturn ($ this ->connectionMock );
49
+ $ this ->resourceMock ->method ('getTableName ' )
50
+ ->willReturnArgument (0 );
46
51
$ this ->generatorMock = $ this ->createMock (Generator::class);
47
52
}
48
53
49
54
/**
50
- * @return \PHPUnit_Framework_MockObject_MockObject
55
+ * @return MockObject
51
56
*/
52
- protected function getVisibleImagesSelectMock (): \ PHPUnit_Framework_MockObject_MockObject
57
+ protected function getVisibleImagesSelectMock (): MockObject
53
58
{
54
59
$ selectMock = $ this ->getMockBuilder (Select::class)
55
60
->disableOriginalConstructor ()
@@ -105,16 +110,21 @@ public function testGetCountAllProductImages(int $imagesCount): void
105
110
]
106
111
);
107
112
108
- $ this ->assertSame ($ imagesCount , $ imageModel ->getCountAllProductImages ());
113
+ $ this ->assertSame (
114
+ $ imagesCount ,
115
+ $ imageModel ->getCountAllProductImages ()
116
+ );
109
117
}
110
118
111
119
/**
112
120
* @param int $imagesCount
113
121
* @param int $batchSize
114
122
* @dataProvider dataProvider
115
123
*/
116
- public function testGetAllProductImages (int $ imagesCount , int $ batchSize ): void
117
- {
124
+ public function testGetAllProductImages (
125
+ int $ imagesCount ,
126
+ int $ batchSize
127
+ ): void {
118
128
$ this ->connectionMock ->expects ($ this ->once ())
119
129
->method ('select ' )
120
130
->willReturn ($ this ->getVisibleImagesSelectMock ());
@@ -125,7 +135,7 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
125
135
->method ('fetchAll ' )
126
136
->will ($ this ->returnCallback ($ fetchResultsCallback ));
127
137
128
- /** @var Select | \PHPUnit_Framework_MockObject_MockObject $selectMock */
138
+ /** @var Select | MockObject $selectMock */
129
139
$ selectMock = $ this ->getMockBuilder (Select::class)
130
140
->disableOriginalConstructor ()
131
141
->getMock ();
@@ -136,8 +146,12 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
136
146
'value_id ' ,
137
147
$ selectMock ,
138
148
$ batchSize ,
139
- \Magento \Framework \DB \Query \BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
140
- )->will ($ this ->returnCallback ($ this ->getBatchIteratorCallback ($ selectMock , $ batchCount )));
149
+ BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
150
+ )->will (
151
+ $ this ->returnCallback (
152
+ $ this ->getBatchIteratorCallback ($ selectMock , $ batchCount )
153
+ )
154
+ );
141
155
142
156
$ imageModel = $ this ->objectManager ->getObject (
143
157
Image::class,
@@ -156,10 +170,13 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
156
170
* @param int $batchSize
157
171
* @return \Closure
158
172
*/
159
- protected function getFetchResultCallbackForBatches (int $ imagesCount , int $ batchSize ): \Closure
160
- {
173
+ protected function getFetchResultCallbackForBatches (
174
+ int $ imagesCount ,
175
+ int $ batchSize
176
+ ): \Closure {
161
177
$ fetchResultsCallback = function () use (&$ imagesCount , $ batchSize ) {
162
- $ batchSize = ($ imagesCount >= $ batchSize ) ? $ batchSize : $ imagesCount ;
178
+ $ batchSize =
179
+ ($ imagesCount >= $ batchSize ) ? $ batchSize : $ imagesCount ;
163
180
$ imagesCount -= $ batchSize ;
164
181
165
182
$ getFetchResults = function ($ batchSize ): array {
@@ -180,16 +197,15 @@ protected function getFetchResultCallbackForBatches(int $imagesCount, int $batch
180
197
}
181
198
182
199
/**
183
- * @param Select | \PHPUnit_Framework_MockObject_MockObject $selectMock
200
+ * @param Select | MockObject $selectMock
184
201
* @param int $batchCount
185
202
* @return \Closure
186
203
*/
187
204
protected function getBatchIteratorCallback (
188
- \ PHPUnit_Framework_MockObject_MockObject $ selectMock ,
205
+ MockObject $ selectMock ,
189
206
int $ batchCount
190
- ): \Closure
191
- {
192
- $ getBatchIteratorCallback = function () use ($ batchCount , $ selectMock ): array {
207
+ ): \Closure {
208
+ $ iteratorCallback = function () use ($ batchCount , $ selectMock ): array {
193
209
$ result = [];
194
210
$ count = $ batchCount ;
195
211
while ($ count ) {
@@ -200,7 +216,7 @@ protected function getBatchIteratorCallback(
200
216
return $ result ;
201
217
};
202
218
203
- return $ getBatchIteratorCallback ;
219
+ return $ iteratorCallback ;
204
220
}
205
221
206
222
/**
0 commit comments