本文整理汇总了PHP中Magento\Framework\Data\Collection::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::expects方法的具体用法?PHP Collection::expects怎么用?PHP Collection::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Data\Collection
的用法示例。
在下文中一共展示了Collection::expects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddFiltersVerifyAddConditionsToRegistry
public function testAddFiltersVerifyAddConditionsToRegistry()
{
$registry = new \Magento\Framework\Registry();
$values = ['sku' => 'simple'];
$this->resourceProvider->expects($this->once())->method('getResource')->willReturn($this->resource);
$this->resourceProvider->expects($this->once())->method('getResourceCollection')->willReturn($this->collection);
$this->resourceProvider->expects($this->once())->method('getAdvancedResultCollection')->willReturn($this->collection);
$this->skuAttribute->expects($this->once())->method('getTable')->will($this->returnValue('catalog_product_entity'));
$this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
$this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
$this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
$this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
$this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
$this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('sku'));
$this->attribute->expects($this->any())->method('getStoreLabel')->will($this->returnValue('SKU'));
$this->attribute->expects($this->any())->method('getFrontendInput')->will($this->returnValue('text'));
$this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->skuAttribute));
$this->attribute->expects($this->any())->method('getBackendType')->will($this->returnValue('static'));
$this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->attribute])));
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
/** @var \Magento\CatalogSearch\Model\Advanced $instance */
$instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection]]);
$instance->addFilters($values);
$this->assertNotNull($registry->registry('advanced_search_conditions'));
}
示例2: testAddFiltersVerifyAddConditionsToRegistry
/**
* @param array $attributes
* @param array $values
* @param string $currentCurrencyCode
* @param string $baseCurrencyCode
* @dataProvider addFiltersDataProvider
*/
public function testAddFiltersVerifyAddConditionsToRegistry(array $attributes, array $values, $currentCurrencyCode = 'GBP', $baseCurrencyCode = 'USD')
{
$registry = new \Magento\Framework\Registry();
$this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
$this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
$this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
$this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
$this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
$this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
$this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator($attributes)));
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$advancedFactory = $this->getMockBuilder('Magento\\CatalogSearch\\Model\\ResourceModel\\AdvancedFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
$advancedFactory->expects($this->once())->method('create')->willReturn($this->resource);
$productCollectionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
$productCollectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
$this->store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn($currentCurrencyCode);
$this->store->expects($this->any())->method('getBaseCurrencyCode')->willReturn($baseCurrencyCode);
$this->currency->expects($this->any())->method('getRate')->with($currentCurrencyCode)->willReturn(1.5);
$currency = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->setMethods(['load', 'format'])->disableOriginalConstructor()->getMock();
$currency->expects($this->any())->method('load')->willReturnSelf();
$currency->expects($this->any())->method('format')->willReturnArgument(0);
$currencyFactory = $this->getMockBuilder('Magento\\Directory\\Model\\CurrencyFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
$currencyFactory->expects($this->any())->method('create')->willReturn($currency);
/** @var \Magento\CatalogSearch\Model\Advanced $instance */
$instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection], 'advancedFactory' => $advancedFactory, 'productCollectionFactory' => $productCollectionFactory, 'storeManager' => $this->storeManager, 'currencyFactory' => $currencyFactory]);
$instance->addFilters($values);
$this->assertNotNull($registry->registry('advanced_search_conditions'));
}
示例3: testGenerate
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData());
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config);
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}
示例4: testGenerate
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$data = $this->getTestData();
$this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
$themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
$themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}