Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit c95ce3c

Browse files
committed
catalog:images:resize fails to process all images -> Possible underlying Magento/Framework/DB/Query/Generator issue - fix code style;
1 parent 546e7ce commit c95ce3c

File tree

1 file changed

+39
-23
lines changed
  • app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product

1 file changed

+39
-23
lines changed

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/ImageTest.php

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\DB\Select;
1414
use Magento\Framework\App\ResourceConnection;
1515
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
16+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
17+
use Magento\Framework\DB\Query\BatchIteratorInterface;
1618

1719
class ImageTest extends \PHPUnit\Framework\TestCase
1820
{
@@ -22,34 +24,37 @@ class ImageTest extends \PHPUnit\Framework\TestCase
2224
protected $objectManager;
2325

2426
/**
25-
* @var AdapterInterface | \PHPUnit_Framework_MockObject_MockObject
27+
* @var AdapterInterface | MockObject
2628
*/
2729
protected $connectionMock;
2830

2931
/**
30-
* @var Generator | \PHPUnit_Framework_MockObject_MockObject
32+
* @var Generator | MockObject
3133
*/
3234
protected $generatorMock;
3335

3436
/**
35-
* @var ResourceConnection | \PHPUnit_Framework_MockObject_MockObject
37+
* @var ResourceConnection | MockObject
3638
*/
3739
protected $resourceMock;
3840

3941
protected function setUp(): void
4042
{
41-
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
43+
$this->objectManager =
44+
new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4245
$this->connectionMock = $this->createMock(AdapterInterface::class);
4346
$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);
4651
$this->generatorMock = $this->createMock(Generator::class);
4752
}
4853

4954
/**
50-
* @return \PHPUnit_Framework_MockObject_MockObject
55+
* @return MockObject
5156
*/
52-
protected function getVisibleImagesSelectMock(): \PHPUnit_Framework_MockObject_MockObject
57+
protected function getVisibleImagesSelectMock(): MockObject
5358
{
5459
$selectMock = $this->getMockBuilder(Select::class)
5560
->disableOriginalConstructor()
@@ -105,16 +110,21 @@ public function testGetCountAllProductImages(int $imagesCount): void
105110
]
106111
);
107112

108-
$this->assertSame($imagesCount, $imageModel->getCountAllProductImages());
113+
$this->assertSame(
114+
$imagesCount,
115+
$imageModel->getCountAllProductImages()
116+
);
109117
}
110118

111119
/**
112120
* @param int $imagesCount
113121
* @param int $batchSize
114122
* @dataProvider dataProvider
115123
*/
116-
public function testGetAllProductImages(int $imagesCount, int $batchSize): void
117-
{
124+
public function testGetAllProductImages(
125+
int $imagesCount,
126+
int $batchSize
127+
): void {
118128
$this->connectionMock->expects($this->once())
119129
->method('select')
120130
->willReturn($this->getVisibleImagesSelectMock());
@@ -125,7 +135,7 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
125135
->method('fetchAll')
126136
->will($this->returnCallback($fetchResultsCallback));
127137

128-
/** @var Select | \PHPUnit_Framework_MockObject_MockObject $selectMock */
138+
/** @var Select | MockObject $selectMock */
129139
$selectMock = $this->getMockBuilder(Select::class)
130140
->disableOriginalConstructor()
131141
->getMock();
@@ -136,8 +146,12 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
136146
'value_id',
137147
$selectMock,
138148
$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+
);
141155

142156
$imageModel = $this->objectManager->getObject(
143157
Image::class,
@@ -156,10 +170,13 @@ public function testGetAllProductImages(int $imagesCount, int $batchSize): void
156170
* @param int $batchSize
157171
* @return \Closure
158172
*/
159-
protected function getFetchResultCallbackForBatches(int $imagesCount, int $batchSize): \Closure
160-
{
173+
protected function getFetchResultCallbackForBatches(
174+
int $imagesCount,
175+
int $batchSize
176+
): \Closure {
161177
$fetchResultsCallback = function () use (&$imagesCount, $batchSize) {
162-
$batchSize = ($imagesCount >= $batchSize) ? $batchSize : $imagesCount;
178+
$batchSize =
179+
($imagesCount >= $batchSize) ? $batchSize : $imagesCount;
163180
$imagesCount -= $batchSize;
164181

165182
$getFetchResults = function ($batchSize): array {
@@ -180,16 +197,15 @@ protected function getFetchResultCallbackForBatches(int $imagesCount, int $batch
180197
}
181198

182199
/**
183-
* @param Select | \PHPUnit_Framework_MockObject_MockObject $selectMock
200+
* @param Select | MockObject $selectMock
184201
* @param int $batchCount
185202
* @return \Closure
186203
*/
187204
protected function getBatchIteratorCallback(
188-
\PHPUnit_Framework_MockObject_MockObject $selectMock,
205+
MockObject $selectMock,
189206
int $batchCount
190-
): \Closure
191-
{
192-
$getBatchIteratorCallback = function () use ($batchCount, $selectMock): array {
207+
): \Closure {
208+
$iteratorCallback = function () use ($batchCount, $selectMock): array {
193209
$result = [];
194210
$count = $batchCount;
195211
while ($count) {
@@ -200,7 +216,7 @@ protected function getBatchIteratorCallback(
200216
return $result;
201217
};
202218

203-
return $getBatchIteratorCallback;
219+
return $iteratorCallback;
204220
}
205221

206222
/**

0 commit comments

Comments
 (0)