8 use \Magento\Framework\Data\Collection\AbstractDb;
22 $this->_resourceModel = new \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIterator();
27 unset($this->_resourceModel);
33 public function testIterate()
39 $callbackMock = $this->createPartialMock(\stdClass::class, [
'callback']);
41 $fetchStrategy = $this->getMockForAbstractClass(
42 \
Magento\Framework\Data\Collection\Db\FetchStrategyInterface::class
47 $entityFactory = $this->createMock(\
Magento\Framework\Data\Collection\EntityFactory::class);
48 $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
51 $collectionMock = $this->getMockBuilder(\
Magento\Framework\Data\Collection\AbstractDb::class)
52 ->setConstructorArgs([$entityFactory,
$logger, $fetchStrategy])
53 ->setMethods([
'clear',
'setPageSize',
'setCurPage',
'count',
'getLastPageNumber',
'getSelect'])
54 ->getMockForAbstractClass();
56 $collectionMock->expects($this->any())->method(
'getSelect')->will($this->returnValue(
$select));
58 $collectionMock->expects($this->exactly($pageCount + 1))->method(
'clear')->will($this->returnSelf());
60 $collectionMock->expects($this->exactly($pageCount))->method(
'setPageSize')->will($this->returnSelf());
62 $collectionMock->expects($this->exactly($pageCount))->method(
'setCurPage')->will($this->returnSelf());
64 $collectionMock->expects($this->exactly($pageCount))->method(
'count')->will($this->returnValue($pageSize));
66 $collectionMock->expects(
67 $this->exactly($pageCount)
71 $this->returnValue($pageCount)
74 for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
75 for ($rowNumber = 1; $rowNumber <= $pageSize; $rowNumber++) {
76 $itemId = ($pageNumber - 1) * $pageSize + $rowNumber;
77 $item = new \Magento\Framework\DataObject([
'id' => $itemId]);
78 $collectionMock->addItem(
$item);
80 $callbackMock->expects($this->at($itemId - 1))->method(
'callback')->with(
$item);
84 $this->_resourceModel->iterate($collectionMock, $pageSize, [[$callbackMock,
'callback']]);