/**
  * @covers \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIterator::iterate
  */
 public function testIterate()
 {
     $pageSize = 2;
     $pageCount = 3;
     /** @var $callbackMock \PHPUnit_Framework_MockObject_MockObject */
     $callbackMock = $this->getMock('stdClass', ['callback']);
     $fetchStrategy = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $entityFactory = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     /** @var $collectionMock AbstractDb|\PHPUnit_Framework_MockObject_MockObject */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->setConstructorArgs([$entityFactory, $logger, $fetchStrategy])->setMethods(['clear', 'setPageSize', 'setCurPage', 'count', 'getLastPageNumber', 'getSelect'])->getMockForAbstractClass();
     $collectionMock->expects($this->any())->method('getSelect')->will($this->returnValue($select));
     $collectionMock->expects($this->exactly($pageCount + 1))->method('clear')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('setPageSize')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('setCurPage')->will($this->returnSelf());
     $collectionMock->expects($this->exactly($pageCount))->method('count')->will($this->returnValue($pageSize));
     $collectionMock->expects($this->exactly($pageCount))->method('getLastPageNumber')->will($this->returnValue($pageCount));
     for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
         for ($rowNumber = 1; $rowNumber <= $pageSize; $rowNumber++) {
             $itemId = ($pageNumber - 1) * $pageSize + $rowNumber;
             $item = new \Magento\Framework\DataObject(['id' => $itemId]);
             $collectionMock->addItem($item);
             $callbackMock->expects($this->at($itemId - 1))->method('callback')->with($item);
         }
     }
     $this->_resourceModel->iterate($collectionMock, $pageSize, [[$callbackMock, 'callback']]);
 }
Exemplo n.º 2
0
 /**
  * Load needed data from customer collection
  *
  * @return void
  */
 public function load()
 {
     if ($this->_isCollectionLoaded == false) {
         $collection = clone $this->_customerCollection;
         $collection->removeAttributeToSelect();
         $tableName = $collection->getResource()->getEntityTable();
         $collection->getSelect()->from($tableName, ['entity_id', 'website_id', 'email']);
         $this->_byPagesIterator->iterate($this->_customerCollection, $this->_pageSize, [[$this, 'addCustomer']]);
         $this->_isCollectionLoaded = true;
     }
 }
Exemplo n.º 3
0
 /**
  * Load exiting custom options data
  *
  * @return $this
  */
 protected function _initOldCustomOptions()
 {
     if (!$this->_oldCustomOptions) {
         $oldCustomOptions = [];
         $optionTitleTable = $this->_tables['catalog_product_option_title'];
         foreach ($this->_storeCodeToId as $storeId) {
             $addCustomOptions = function (\Magento\Catalog\Model\Product\Option $customOption) use(&$oldCustomOptions, $storeId) {
                 $productId = $customOption->getProductId();
                 if (!isset($oldCustomOptions[$productId])) {
                     $oldCustomOptions[$productId] = [];
                 }
                 if (isset($oldCustomOptions[$productId][$customOption->getId()])) {
                     $oldCustomOptions[$productId][$customOption->getId()]['titles'][$storeId] = $customOption->getTitle();
                 } else {
                     $oldCustomOptions[$productId][$customOption->getId()] = ['titles' => [$storeId => $customOption->getTitle()], 'type' => $customOption->getType()];
                 }
             };
             /** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Option\Collection */
             $this->_optionCollection->reset();
             $this->_optionCollection->getSelect()->join(['option_title' => $optionTitleTable], 'option_title.option_id = main_table.option_id', ['title' => 'title', 'store_id' => 'store_id'])->where('option_title.store_id = ?', $storeId);
             $this->_byPagesIterator->iterate($this->_optionCollection, $this->_pageSize, [$addCustomOptions]);
         }
         $this->_oldCustomOptions = $oldCustomOptions;
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Iterate through given collection page by page and export items
  *
  * @param \Magento\Framework\Data\Collection\AbstractDb $collection
  * @return void
  */
 protected function _exportCollectionByPages(\Magento\Framework\Data\Collection\AbstractDb $collection)
 {
     $this->_byPagesIterator->iterate($collection, $this->_pageSize, [[$this, 'exportItem']]);
 }