当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::toArray方法代码示例

本文整理汇总了PHP中Magento\Framework\Data\Collection::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::toArray方法的具体用法?PHP Collection::toArray怎么用?PHP Collection::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Data\Collection的用法示例。


在下文中一共展示了Collection::toArray方法的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());
 }
开发者ID:,项目名称:,代码行数:34,代码来源:


注:本文中的Magento\Framework\Data\Collection::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。