Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function fetchAll(\Zend_Db_Select $select, array $bindParams = array())
 {
     $cacheId = $this->_getSelectCacheId($select);
     $result = $this->_cache->load($cacheId);
     if ($result) {
         $result = unserialize($result);
     } else {
         $result = $this->_fetchStrategy->fetchAll($select, $bindParams);
         $this->_cache->save(serialize($result), $cacheId, $this->_cacheTags, $this->_cacheLifetime);
     }
     return $result;
 }
Exemple #2
0
 /**
  * Fetch all statement
  *
  * @return array
  */
 public function fetchAll()
 {
     if ($this->data === null) {
         $select = $this->getSelect();
         $this->data = $this->fetchStrategy->fetchAll($select, $this->bindParams);
     }
     return $this->data;
 }
Exemple #3
0
 /**
  * @dataProvider getItemsDataProvider
  */
 public function testRemoveItemByKey($values, $count)
 {
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue($values));
     $testId = array_pop($values)['id'];
     $this->assertCount($count, $this->model->getItems());
     $this->assertNotNull($this->model->getItemById($testId));
     $this->model->removeItemByKey($testId);
     $this->assertCount($count - 1, $this->model->getItems());
     $this->assertNull($this->model->getItemById($testId));
 }
 /**
  * Fetch collection data
  *
  * @param Select $select
  * @return array
  */
 protected function _fetchAll(Select $select)
 {
     $data = $this->_fetchStrategy->fetchAll($select, $this->_bindParams);
     if ($this->extensionAttributesJoinProcessor) {
         foreach ($data as $key => $dataItem) {
             $data[$key] = $this->extensionAttributesJoinProcessor->extractExtensionAttributes($this->_itemObjectClass, $dataItem);
         }
     }
     return $data;
 }
Exemple #5
0
 public function setUp()
 {
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->historyItemMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', ['__wakeup', 'addData'], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getReadConnection', 'getMainTable', 'getTable', '__wakeup']);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->entityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $data = [['data']];
     $this->historyItemMock->expects($this->once())->method('addData')->with($this->equalTo($data[0]))->will($this->returnValue($this->historyItemMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->entityFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->historyItemMock));
     $logger = $this->getMock('Magento\\Framework\\Logger', [], [], '', false);
     $this->collection = new \Magento\Sales\Model\Resource\Order\Status\History\Collection($this->entityFactoryMock, $logger, $this->fetchStrategyMock, $this->eventManagerMock, $this->connectionMock, $this->resourceMock);
 }
Exemple #6
0
 public function testToOptionHash()
 {
     $data = [10 => 'test'];
     $adapterMock = $this->getMock('Zend_Db_Adapter_Pdo_Mysql', ['select', 'query'], [], '', false);
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], ['adapter' => $adapterMock]);
     $adapterMock->expects($this->once())->method('select')->will($this->returnValue($selectMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->with($selectMock, [])->will($this->returnValue([$data]));
     $objectMock = $this->getMock('Magento\\Framework\\Object', ['addData', 'setIdFieldName', 'getData'], []);
     $objectMock->expects($this->once())->method('addData')->with($data);
     $objectMock->expects($this->any())->method('getData')->will($this->returnValueMap([[null, null, 10], ['name', null, 'test']]));
     $this->entityFactoryMock->expects($this->once())->method('create')->with('Magento\\Framework\\Object')->will($this->returnValue($objectMock));
     $this->collection->setConnection($adapterMock);
     $this->collection->loadData(false, false);
     $this->collection->loadData(false, false);
     $this->assertEquals($data, $this->collection->toOptionHash());
 }
Exemple #7
0
 /**
  * Run test fetchAll method
  *
  * @return void
  */
 public function testFetchAll()
 {
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue('return-value'));
     $this->assertEquals('return-value', $this->query->fetchAll());
 }
Exemple #8
0
 /**
  * Fetch collection data
  *
  * @param \Zend_Db_Select $select
  * @return array
  */
 protected function _fetchAll(\Zend_Db_Select $select)
 {
     return $this->_fetchStrategy->fetchAll($select, $this->_bindParams);
 }