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


PHP ProductRepositoryInterface::expects方法代码示例

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


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

示例1: testGetList

 public function testGetList()
 {
     $productSku = 'downloadable_sku';
     $sampleData = ['id' => 324, 'store_title' => 'rock melody sample', 'title' => 'just melody sample', 'sort_order' => 21, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg'];
     $sampleMock = $this->getMock('\\Magento\\Downloadable\\Model\\Sample', ['getId', 'getStoreTitle', 'getTitle', 'getSampleType', 'getSampleFile', 'getSampleUrl', 'getSortOrder', 'getData', '__wakeup'], [], '', false);
     $sampleInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\SampleInterface');
     $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock));
     $this->productTypeMock->expects($this->once())->method('getSamples')->with($this->productMock)->will($this->returnValue([$sampleMock]));
     $this->setSampleAssertions($sampleMock, $sampleData);
     $this->sampleFactoryMock->expects($this->once())->method('create')->willReturn($sampleInterfaceMock);
     $this->assertEquals([$sampleInterfaceMock], $this->service->getList($productSku));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:12,代码来源:SampleRepositoryTest.php

示例2: testGetProductInfo

 public function testGetProductInfo()
 {
     $productId = 3;
     $storeId = 1;
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue(new \Magento\Framework\Object(['id' => $storeId])));
     $this->requestMock->expects($this->once())->method('getParam')->with('id', false)->willReturn($productId);
     $productMock = $this->getMock('Magento\\Catalog\\Api\\Data\\ProductInterface');
     $this->productRepository->expects($this->once())->method('getById')->with($productId, false, $storeId)->willReturn($productMock);
     $this->assertSame($productMock, $this->object->getProductInfo());
 }
开发者ID:opexsw,项目名称:magento2,代码行数:10,代码来源:FormTest.php

示例3: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->getMockForAbstractClass();
     $this->productLinkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass();
     $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->productRepositoryMock->expects($this->any())->method('getById')->willReturn($this->productMock);
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:12,代码来源:AbstractDataProviderTest.php

示例4: setUp

 protected function setUp()
 {
     $this->category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false);
     $productMethods = ['__wakeup', 'getData', 'getUrlKey', 'getName', 'formatUrlKey', 'getId', 'load', 'setStoreId'];
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', $productMethods, [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->categoryUrlPathGenerator = $this->getMock('Magento\\CatalogUrlRewrite\\Model\\CategoryUrlPathGenerator', [], [], '', false);
     $this->productRepository = $this->getMock('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $this->productRepository->expects($this->any())->method('getById')->willReturn($this->product);
     $this->productUrlPathGenerator = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Model\\ProductUrlPathGenerator', ['storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator, 'productRepository' => $this->productRepository]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:ProductUrlPathGeneratorTest.php

示例5: testAfterInitialize

 public function testAfterInitialize()
 {
     $productMock = $this->getProductMock();
     $configurableMatrix = [['newProduct' => true, 'id' => 'product1'], ['newProduct' => false, 'id' => 'product2', 'status' => 'simple2_status', 'sku' => 'simple2_sku', 'name' => 'simple2_name', 'price' => '3.33', 'configurable_attribute' => 'simple2_configurable_attribute', 'weight' => '5.55', 'media_gallery' => 'simple2_media_gallery', 'swatch_image' => 'simple2_swatch_image', 'small_image' => 'simple2_small_image', 'thumbnail' => 'simple2_thumbnail', 'image' => 'simple2_image'], ['newProduct' => false, 'id' => 'product3', 'qty' => '3']];
     $configurations = ['product2' => ['status' => 'simple2_status', 'sku' => 'simple2_sku', 'name' => 'simple2_name', 'price' => '3.33', 'configurable_attribute' => 'simple2_configurable_attribute', 'weight' => '5.55', 'media_gallery' => 'simple2_media_gallery', 'swatch_image' => 'simple2_swatch_image', 'small_image' => 'simple2_small_image', 'thumbnail' => 'simple2_thumbnail', 'image' => 'simple2_image'], 'product3' => ['quantity_and_stock_status' => ['qty' => '3']]];
     /** @var Product[]|\PHPUnit_Framework_MockObject_MockObject[] $productMocks */
     $productMocks = ['product2' => $this->getProductMock($configurations['product2'], true), 'product3' => $this->getProductMock($configurations['product3'])];
     $this->requestMock->expects(static::any())->method('getParam')->willReturnMap([['store', 0, 0], ['configurable-matrix', [], $configurableMatrix]]);
     $this->variationHandlerMock->expects(static::once())->method('duplicateImagesForVariations')->with($configurations)->willReturn($configurations);
     $this->productRepositoryMock->expects(static::any())->method('getById')->willReturnMap([['product2', false, 0, false, $productMocks['product2']], ['product3', false, 0, false, $productMocks['product3']]]);
     $this->variationHandlerMock->expects(static::any())->method('processMediaGallery')->willReturnMap([[$productMocks['product2'], $configurations['product2'], $configurations['product2']], [$productMocks['product3'], $configurations['product3'], $configurations['product3']]]);
     $this->assertSame($productMock, $this->updateConfigurations->afterInitialize($this->subjectMock, $productMock));
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:13,代码来源:UpdateConfigurationsTest.php

示例6: createSwatchProduct

 protected function createSwatchProduct($product)
 {
     if (gettype($product) == 'integer') {
         $this->productRepoMock->expects($this->any())->method('getById')->with(95)->willReturn($this->productMock);
     }
     $this->getSwatchAttributes();
 }
开发者ID:vv-team,项目名称:foodo,代码行数:7,代码来源:DataTest.php

示例7: testAroundSave

 public function testAroundSave()
 {
     $productId = 5494;
     $websiteId = 1;
     $storeId = 2;
     $sku = 'my product that needs saving';
     $defaultScopeId = 100;
     $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($defaultScopeId);
     $this->stockRegistry->expects($this->once())->method('getStock')->with($defaultScopeId)->willReturn($this->defaultStock);
     $this->product->expects($this->once())->method('getExtensionAttributes')->willReturn($this->productExtension);
     $this->productExtension->expects($this->once())->method('getStockItem')->willReturn($this->stockItem);
     $storedStockItem = $this->getMockBuilder(StockItemInterface::class)->setMethods(['getItemId'])->getMockForAbstractClass();
     $storedStockItem->expects($this->once())->method('getItemId')->willReturn(500);
     $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($storedStockItem);
     $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
     $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);
     $this->product->expects($this->exactly(2))->method('getId')->willReturn($productId);
     $this->product->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $this->product->expects($this->atLeastOnce())->method('getSku')->willReturn($sku);
     $this->stockItem->expects($this->once())->method('setProductId')->with($productId);
     $this->stockItem->expects($this->once())->method('setWebsiteId')->with($websiteId);
     $this->stockRegistry->expects($this->once())->method('updateStockItemBySku')->with($sku, $this->stockItem);
     $newProductMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->disableOriginalConstructor()->getMock();
     $this->productRepository->expects($this->once())->method('get')->with($sku, false, $storeId, true)->willReturn($newProductMock);
     $this->assertEquals($newProductMock, $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:27,代码来源:AroundProductRepositorySaveTest.php

示例8: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->locatorMock = $this->getMockBuilder(LocatorInterface::class)->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getTypeId'])->getMockForAbstractClass();
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->productMock->expects($this->any())->method('getTypeId')->willReturn(GroupedProductType::TYPE_CODE);
     $this->linkedProductMock = $this->getMockBuilder(ProductInterface::class)->setMethods(['getId', 'getName', 'getPrice'])->getMockForAbstractClass();
     $this->linkedProductMock->expects($this->any())->method('getId')->willReturn(self::LINKED_PRODUCT_ID);
     $this->linkedProductMock->expects($this->any())->method('getName')->willReturn(self::LINKED_PRODUCT_NAME);
     $this->linkedProductMock->expects($this->any())->method('getPrice')->willReturn(self::LINKED_PRODUCT_PRICE);
     $this->linkMock = $this->getMockBuilder(ProductLinkInterface::class)->setMethods(['getLinkType', 'getLinkedProductSku', 'getPosition', 'getExtensionAttributes'])->getMockForAbstractClass();
     $this->linkExtensionMock = $this->getMockBuilder(ProductLinkExtensionInterface::class)->setMethods(['getQty'])->getMockForAbstractClass();
     $this->linkExtensionMock->expects($this->any())->method('getQty')->willReturn(self::LINKED_PRODUCT_QTY);
     $this->linkMock->expects($this->any())->method('getExtensionAttributes')->willReturn($this->linkExtensionMock);
     $this->linkMock->expects($this->any())->method('getPosition')->willReturn(self::LINKED_PRODUCT_POSITION);
     $this->linkMock->expects($this->any())->method('getLinkedProductSku')->willReturn(self::LINKED_PRODUCT_SKU);
     $this->linkMock->expects($this->any())->method('getLinkType')->willReturn(Grouped::LINK_TYPE);
     $this->linkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->setMethods(['getList'])->getMockForAbstractClass();
     $this->linkRepositoryMock->expects($this->any())->method('getList')->with($this->productMock)->willReturn([$this->linkMock]);
     $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->any())->method('get')->with(self::LINKED_PRODUCT_SKU)->willReturn($this->linkedProductMock);
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:GroupedTest.php

示例9: testItEnablesADisabledProduct

 public function testItEnablesADisabledProduct()
 {
     $mockProduct = $this->createMockDisabledProduct('test');
     $mockProduct->expects($this->once())->method('setStatus')->with(ProductStatus::STATUS_ENABLED);
     $this->mockProductRepository->method('get')->willReturn($mockProduct);
     $this->mockProductRepository->expects($this->once())->method('save')->with($mockProduct);
     $this->productStatusAdapter->enableProductWithSku('test');
 }
开发者ID:nhp,项目名称:MageTitans_ProductStatus,代码行数:8,代码来源:ProductStatusAdapterTest.php

示例10: testGetProduct

 public function testGetProduct()
 {
     $productId = 1;
     $storeId = 0;
     $this->model->setData('product_id', $productId);
     $this->model->setData('store_id', $storeId);
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $productMock->expects($this->any())->method('setFinalPrice')->with(null);
     $productMock->expects($this->any())->method('setCustomOprtions')->with([]);
     $this->productRepository->expects($this->once())->method('getById')->willReturn($productMock);
     $this->assertEquals($productMock, $this->model->getProduct());
 }
开发者ID:nja78,项目名称:magento2,代码行数:12,代码来源:ItemTest.php

示例11: testGetList

 public function testGetList()
 {
     $productSku = 'downloadable_sku';
     $linkData = ['id' => 324, 'store_title' => 'rock melody', 'title' => 'just melody', 'price' => 23, 'number_of_downloads' => 3, 'sort_order' => 21, 'is_shareable' => 2, 'sample_type' => 'file', 'sample_url' => null, 'sample_file' => '/r/o/rock.melody.ogg', 'link_type' => 'url', 'link_url' => 'http://link.url', 'link_file' => null];
     $linkMock = $this->getMock('Magento\\Downloadable\\Model\\Link', ['getId', 'getStoreTitle', 'getTitle', 'getPrice', 'getNumberOfDownloads', 'getSortOrder', 'getIsShareable', 'getData', '__wakeup', 'setId'], [], '', false);
     $linkInterfaceMock = $this->getMock('\\Magento\\Downloadable\\Api\\Data\\LinkInterface');
     $this->repositoryMock->expects($this->once())->method('get')->with($productSku)->will($this->returnValue($this->productMock));
     $this->productTypeMock->expects($this->once())->method('getLinks')->with($this->productMock)->will($this->returnValue([$linkMock]));
     $this->setLinkAssertions($linkMock, $linkData);
     $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkInterfaceMock);
     $this->assertEquals([$linkInterfaceMock], $this->service->getList($productSku));
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:12,代码来源:LinkRepositoryTest.php

示例12: testExecuteWithNonVisibleProduct

 public function testExecuteWithNonVisibleProduct()
 {
     $productId = 11;
     $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($productId);
     /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
     $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(false);
     /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */
     $forwardMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Forward')->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])->willReturn($forwardMock);
     $forwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf();
     $this->assertEquals($forwardMock, $this->model->execute());
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:14,代码来源:SendTest.php

示例13: testGetProductByAttributesReturnFirstItem

 public function testGetProductByAttributesReturnFirstItem()
 {
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId'])->disableOriginalConstructor()->getMock();
     $firstItemMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getId'])->disableOriginalConstructor()->getMock();
     $productCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Product\\Collection')->setMethods(['setFlag', 'setProductFilter', 'addStoreFilter', 'addAttributeToSelect', 'addAttributeToFilter', 'getFirstItem'])->disableOriginalConstructor()->getMock();
     $this->_productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($productCollection));
     $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf());
     $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock);
     $firstItemMock->expects($this->any())->method('getId')->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(3)->willReturn($firstItemMock);
     $this->assertEquals($firstItemMock, $this->_model->getProductByAttributes($this->attributeData, $productMock));
 }
开发者ID:nja78,项目名称:magento2,代码行数:15,代码来源:ConfigurableTest.php

示例14: testGetProductsWithFilter

 public function testGetProductsWithFilter()
 {
     $products = ['Product1', 'Product2'];
     $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass();
     $this->request->expects($this->exactly(2))->method('getParam')->with($this->equalTo('type'))->willReturn('FilterProductType');
     $this->filterBuilder->expects($this->once())->method('setField')->with('type_id')->willReturnSelf();
     $this->filterBuilder->expects($this->once())->method('setValue')->with($this->equalTo('FilterProductType'))->willReturnSelf();
     $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
     $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
     $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with($this->equalTo([$filter]))->willReturnSelf();
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $this->productRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($products);
     $result = $this->block->getProducts();
     $this->assertEquals($products, $result);
 }
开发者ID:luo3555,项目名称:magento2-samples,代码行数:15,代码来源:ProductListTest.php

示例15: testGetProductMediaGallery

 /**
  * @dataProvider dataForMediaGallery
  */
 public function testGetProductMediaGallery($mediaGallery, $image)
 {
     $this->productMock->expects($this->once())->method('getMediaAttributeValues')->willReturn($mediaGallery);
     $this->productMock->expects($this->any())->method('getId')->willReturn(95);
     $this->imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$this->productMock, 'product_page_image_large', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_medium', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_small', [], $this->imageHelperMock]]);
     $this->imageHelperMock->expects($this->any())->method('setImageFile')->with($image)->willReturnSelf();
     $this->imageHelperMock->expects($this->any())->method('constrainOnly')->willReturnSelf();
     $this->imageHelperMock->expects($this->any())->method('keepAspectRatio')->willReturnSelf();
     $this->imageHelperMock->expects($this->any())->method('keepFrame')->willReturnSelf();
     $this->imageHelperMock->expects($this->any())->method('getUrl')->willReturn('http://full_path_to_image/magento1.png');
     $this->productRepoMock->expects($this->any())->method('getById')->with(95)->willReturn($this->productMock);
     $mediaObject = $this->getMock('\\Magento\\Framework\\DataObject', [], [], '', false);
     $iterator = new \ArrayIterator([$mediaObject]);
     $mediaCollectionMock = $this->getMock('\\Magento\\Framework\\Data\\Collection', [], [], '', false);
     $mediaCollectionMock->expects($this->any())->method('getIterator')->willReturn($iterator);
     $mediaObject->method('getData')->withConsecutive(['value_id'], ['file'])->willReturnOnConsecutiveCalls(0, $image);
     $this->productMock->method('getMediaGalleryImages')->willReturn($mediaCollectionMock);
     $this->swatchHelperObject->getProductMediaGallery($this->productMock);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:22,代码来源:DataTest.php


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