/** * @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)); }
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); }
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()); }
/** * 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()); }