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


PHP Collection::expects方法代码示例

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


在下文中一共展示了Collection::expects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _initConfigurableData

 protected function _initConfigurableData()
 {
     $productIds = [1, 2, 3];
     $attributes = [[['pricing_is_percent' => true, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 12345], ['pricing_is_percent' => false, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 12345]]];
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getTypeInstance', '__wakeup'], [], '', false);
     $productMock->expects($this->any())->method('getId')->will($this->returnValue(11));
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $typeInstanceMock->expects($this->any())->method('getConfigurableOptions')->will($this->returnValue($attributes));
     $productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $this->_collectionMock->expects($this->at(0))->method('addAttributeToFilter')->with('entity_id', ['in' => $productIds])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(1))->method('addAttributeToFilter')->with('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(2))->method('fetchItem')->will($this->returnValue($productMock));
     $this->_collectionMock->expects($this->at(3))->method('fetchItem')->will($this->returnValue(false));
     $this->_model->prepareData($this->_collectionMock, $productIds);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:RowCustomizerTest.php

示例2: setUp

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\Object(['id' => 1, 'attribute_set_name' => 'Default', '_attribute_set' => 'Default']);
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([$item]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection', ['setAttributeSetFilter'], [], '', false);
     $superAttributes = [];
     foreach ($this->_getSuperAttributes() as $superAttribute) {
         $item = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isStatic'], $superAttribute, '', false);
         $item->setData($superAttribute);
         $item->method('isStatic')->will($this->returnValue(false));
         $superAttributes[] = $item;
     }
     $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attrCollection));
     $this->attrCollection->expects($this->any())->method('setAttributeSetFilter')->will($this->returnValue($superAttributes));
     $this->_entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getConnection', 'getAttrSetIdToName', 'getAttributeOptions'], [], '', false);
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->_connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getAdapter'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $this->_connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->_connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->_connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->_connection->expects($this->any())->method('fetchPairs')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->_entityModel->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->productCollectionFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection', ['addFieldToFilter', 'addAttributeToSelect'], [], '', false);
     $products = [];
     $testProducts = [['id' => 1, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 2, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 20, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1]];
     foreach ($testProducts as $product) {
         $item = $this->getMock('\\Magento\\Framework\\Object', ['getAttributeSetId'], [], '', false);
         $item->setData($product);
         $item->expects($this->any())->method('getAttributeSetId')->willReturn(4);
         $products[] = $item;
     }
     $this->productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnValue($products));
     $this->_entityModel->expects($this->any())->method('getAttributeOptions')->will($this->returnValue(['attr2val1' => '1', 'attr2val2' => '2', 'attr2val3' => '3', 'testattr3v1' => '4', 'testattr30v1' => '4', 'testattr3v2' => '5', 'testattr3v3' => '6']));
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableImportExport\\Model\\Import\\Product\\Type\\Configurable', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'resource' => $this->resource, 'productColFac' => $this->productCollectionFactory]);
 }
开发者ID:nja78,项目名称:magento2,代码行数:57,代码来源:ConfigurableTest.php

示例3: testGetProductAllCollection

 /**
  * Test protected `_getProductCollection` and `getPageSize` methods via public `toHtml` method,
  * for display_type == DISPLAY_TYPE_ALL_PRODUCTS.
  *
  * @param bool $pagerEnable
  * @param int $productsCount
  * @param int $productsPerPage
  * @param int $expectedPageSize
  * @dataProvider getProductCollectionDataProvider
  */
 public function testGetProductAllCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
 {
     $this->generalGetProductCollection();
     $this->productCollection->expects($this->atLeastOnce())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
     $this->startTestGetProductCollection(NewWidget::DISPLAY_TYPE_ALL_PRODUCTS, $pagerEnable, $productsCount, $productsPerPage);
 }
开发者ID:nja78,项目名称:magento2,代码行数:16,代码来源:NewWidgetTest.php


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