本文整理汇总了PHP中Magento\Framework\Data\Collection::getLastItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::getLastItem方法的具体用法?PHP Collection::getLastItem怎么用?PHP Collection::getLastItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Data\Collection
的用法示例。
在下文中一共展示了Collection::getLastItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPossibleFlowWithItem
public function testPossibleFlowWithItem()
{
$firstItemMock = $this->getMock('Magento\\Framework\\Object', [], [], '', false);
$secondItemMock = $this->getMock('Magento\\Framework\\Object', [], [], '', false);
$requiredFields = ['required_field_one', 'required_field_two'];
$arrItems = ['totalRecords' => 1, 'items' => [0 => 'value']];
$items = ['item_id' => $firstItemMock, 0 => $secondItemMock];
$firstItemMock->expects($this->exactly(2))->method('getId')->will($this->returnValue('item_id'));
$firstItemMock->expects($this->atLeastOnce())->method('getData')->with('colName')->will($this->returnValue('first_value'));
$secondItemMock->expects($this->atLeastOnce())->method('getData')->with('colName')->will($this->returnValue('second_value'));
$firstItemMock->expects($this->once())->method('toArray')->with($requiredFields)->will($this->returnValue('value'));
/** add items and set them values */
$this->_model->addItem($firstItemMock);
$this->assertEquals($arrItems, $this->_model->toArray($requiredFields));
$this->_model->addItem($secondItemMock);
$this->_model->setDataToAll('column', 'value');
/** get items by column name */
$this->assertEquals(['first_value', 'second_value'], $this->_model->getColumnValues('colName'));
$this->assertEquals([$secondItemMock], $this->_model->getItemsByColumnValue('colName', 'second_value'));
$this->assertEquals($firstItemMock, $this->_model->getItemByColumnValue('colName', 'second_value'));
$this->assertEquals([], $this->_model->getItemsByColumnValue('colName', 'non_existing_value'));
$this->assertEquals(null, $this->_model->getItemByColumnValue('colName', 'non_existing_value'));
/** get items */
$this->assertEquals(['item_id', 0], $this->_model->getAllIds());
$this->assertEquals($firstItemMock, $this->_model->getFirstItem());
$this->assertEquals($secondItemMock, $this->_model->getLastItem());
$this->assertEquals($items, $this->_model->getItems('item_id'));
/** remove existing items */
$this->assertNull($this->_model->getItemById('not_existing_item_id'));
$this->_model->removeItemByKey('item_id');
$this->assertEquals([$secondItemMock], $this->_model->getItems());
$this->_model->removeAllItems();
$this->assertEquals([], $this->_model->getItems());
}