本文整理匯總了PHP中Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectManager::getCollectionMock方法的具體用法?PHP ObjectManager::getCollectionMock怎麽用?PHP ObjectManager::getCollectionMock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\TestFramework\Unit\Helper\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getCollectionMock方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetItems
public function testGetItems()
{
$optionId = 1;
$optionData = ['title' => 'test title'];
$productSku = 'product_sku';
$productMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductInterface');
$productMock->expects($this->once())->method('getSku')->willReturn($productSku);
$optionMock = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getOptionId', 'getData', 'getTitle', 'getDefaultTitle'], [], '', false);
$optionsCollMock = $this->objectManager->getCollectionMock('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', [$optionMock]);
$this->typeMock->expects($this->once())->method('getOptionsCollection')->with($productMock)->willReturn($optionsCollMock);
$optionMock->expects($this->exactly(2))->method('getOptionId')->willReturn($optionId);
$optionMock->expects($this->once())->method('getData')->willReturn($optionData);
$optionMock->expects($this->once())->method('getTitle')->willReturn(null);
$optionMock->expects($this->once())->method('getDefaultTitle')->willReturn($optionData['title']);
$linkMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\LinkInterface');
$this->linkListMock->expects($this->once())->method('getItems')->with($productMock, $optionId)->willReturn([$linkMock]);
$newOptionMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface');
$this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($newOptionMock, $optionData, '\\Magento\\Bundle\\Api\\Data\\OptionInterface')->willReturnSelf();
$newOptionMock->expects($this->once())->method('setOptionId')->with($optionId)->willReturnSelf();
$newOptionMock->expects($this->once())->method('setTitle')->with($optionData['title'])->willReturnSelf();
$newOptionMock->expects($this->once())->method('setSku')->with($productSku)->willReturnSelf();
$newOptionMock->expects($this->once())->method('setProductLinks')->with([$linkMock])->willReturnSelf();
$this->optionFactoryMock->expects($this->once())->method('create')->willReturn($newOptionMock);
$this->assertEquals([$newOptionMock], $this->model->getItems($productMock));
}
示例2: setUp
protected function setUp()
{
$this->objectManager = new ObjectManager($this);
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock();
$this->collectionMock = $this->objectManager->getCollectionMock(Collection::class, []);
$this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
$this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($this->collectionMock);
$this->model = $this->objectManager->getObject(ReviewDataProvider::class, ['name' => 'testName', 'primaryFieldName' => 'testPrimaryFieldName', 'requestFieldName' => 'testRequestFieldName', 'meta' => [], 'data' => [], 'collectionFactory' => $this->collectionFactoryMock, 'request' => $this->requestMock]);
}
示例3: testGetListReturnsTheListOfActiveCheckoutAgreements
public function testGetListReturnsTheListOfActiveCheckoutAgreements()
{
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE, null)->will($this->returnValue(true));
$agreementDataObject = $this->getMock('Magento\\CheckoutAgreements\\Model\\Agreement', [], [], '', false);
$storeId = 1;
$storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId));
$this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
$collectionMock = $this->objectManager->getCollectionMock('Magento\\CheckoutAgreements\\Model\\Resource\\Agreement\\Collection', [$agreementDataObject]);
$this->factoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
$collectionMock->expects($this->once())->method('addStoreFilter')->with($storeId);
$collectionMock->expects($this->once())->method('addFieldToFilter')->with('is_active', 1);
$this->assertEquals([$agreementDataObject], $this->model->getList());
}
示例4: testGetOptions
public function testGetOptions()
{
$optionInstanceMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Option')->disableOriginalConstructor()->getMock();
$optionFactory = $this->getMock('Magento\\Catalog\\Model\\Product\\OptionFactory', ['create'], [], '', false);
$optionFactory->expects($this->any())->method('create')->willReturn($optionInstanceMock);
$joinProcessorMock = $this->getMockBuilder('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface')->disableOriginalConstructor()->getMock();
// the productModel
$productModel = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product', ['catalogProductOptionFactory' => $optionFactory, 'joinProcessor' => $joinProcessorMock]);
$productModel->setHasOptions(true);
$option1Id = 2;
$optionMock1 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product\\Option')->disableOriginalConstructor()->setMethods(['getId', 'setProduct'])->getMock();
$optionMock1->expects($this->once())->method('getId')->willReturn($option1Id);
$optionMock1->expects($this->once())->method('setProduct')->with($productModel)->willReturn($option1Id);
$option2Id = 3;
$optionMock2 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product\\Option')->disableOriginalConstructor()->setMethods(['getId', 'setProduct'])->getMock();
$optionMock2->expects($this->once())->method('getId')->willReturn($option2Id);
$optionMock1->expects($this->once())->method('setProduct')->with($productModel)->willReturn($option1Id);
$optionColl = $this->objectManagerHelper->getCollectionMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Collection', [$optionMock1, $optionMock2]);
$optionInstanceMock->expects($this->once())->method('getProductOptionCollection')->with($productModel)->willReturn($optionColl);
$joinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Collection'));
$expectedOptions = [$option1Id => $optionMock1, $option2Id => $optionMock2];
$this->assertEquals($expectedOptions, $productModel->getOptions());
//Calling the method again, empty options array will be returned
$productModel->setOptions([]);
$this->assertEquals([], $productModel->getOptions());
}
示例5: setUp
protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$taxClass = $this->getMockBuilder('Magento\\Tax\\Model\\ClassModel')->disableOriginalConstructor()->getMock();
$taxClass->method('getClassName')->will($this->returnValue(self::TEST_TAX_CLASS_NAME));
$taxClass->method('getId')->will($this->returnValue(self::TEST_TAX_CLASS_ID));
$taxClassCollection = $this->objectManagerHelper->getCollectionMock('Magento\\Tax\\Model\\ResourceModel\\TaxClass\\Collection', [$taxClass]);
$taxClassCollectionFactory = $this->getMock('Magento\\Tax\\Model\\ResourceModel\\TaxClass\\CollectionFactory', ['create'], [], '', false);
$taxClassCollectionFactory->method('create')->will($this->returnValue($taxClassCollection));
$anotherTaxClass = $this->getMockBuilder('Magento\\Tax\\Model\\ClassModel')->disableOriginalConstructor()->getMock();
$anotherTaxClass->method('getClassName')->will($this->returnValue(self::TEST_TAX_CLASS_NAME));
$anotherTaxClass->method('getId')->will($this->returnValue(self::TEST_JUST_CREATED_TAX_CLASS_ID));
$taxClassFactory = $this->getMock('Magento\\Tax\\Model\\ClassModelFactory', ['create'], [], '', false);
$taxClassFactory->method('create')->will($this->returnValue($anotherTaxClass));
$this->taxClassProcessor = new \Magento\CatalogImportExport\Model\Import\Product\TaxClassProcessor($taxClassCollectionFactory, $taxClassFactory);
$this->product = $this->getMockForAbstractClass('Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType', [], '', false);
}
示例6: setUp
protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$childCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->getMock();
$childCategory->method('getId')->will($this->returnValue(self::CHILD_CATEGORY_ID));
$childCategory->method('getName')->will($this->returnValue('Child'));
$childCategory->method('getPath')->will($this->returnValue(self::PARENT_CATEGORY_ID . CategoryProcessor::DELIMITER_CATEGORY . self::CHILD_CATEGORY_ID));
$parentCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->getMock();
$parentCategory->method('getId')->will($this->returnValue(self::PARENT_CATEGORY_ID));
$parentCategory->method('getName')->will($this->returnValue('Parent'));
$parentCategory->method('getPath')->will($this->returnValue(self::PARENT_CATEGORY_ID));
$categoryCollection = $this->objectManagerHelper->getCollectionMock('Magento\\Catalog\\Model\\Resource\\Category\\Collection', [self::PARENT_CATEGORY_ID => $parentCategory, self::CHILD_CATEGORY_ID => $childCategory]);
$map = [[self::PARENT_CATEGORY_ID, $parentCategory], [self::CHILD_CATEGORY_ID, $childCategory]];
$categoryCollection->expects($this->any())->method('getItemById')->will($this->returnValueMap($map));
$categoryColFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', ['create'], [], '', false);
$categoryColFactory->method('create')->will($this->returnValue($categoryCollection));
$categoryFactory = $this->getMock('Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false);
$categoryFactory->method('create')->will($this->returnValue($childCategory));
$this->categoryProcessor = new \Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor($categoryColFactory, $categoryFactory);
}
示例7: testBuildPositive
/**
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testBuildPositive()
{
//prepare mocks and data samples
$instance = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', ['setStoreFilter', 'getOptionsCollection', 'getSelectionsCollection', 'getOptionsIds'], [], '', false);
$option = $this->getMock('Magento\\Bundle\\Model\\Option', ['getSelections', '__wakeup', 'getData'], [], '', false);
$options = [$option];
$optionCollection = $this->objectManager->getCollectionMock('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', $options);
$optionRawData = [['required' => true, 'position' => 100, 'type' => 'someType', 'title' => 'title', 'delete' => '']];
$selectionRawData = [[['product_id' => 123, 'position' => 500, 'is_default' => false, 'selection_price_type' => 'priceType', 'selection_price_value' => 'priceVal', 'selection_qty' => 21, 'selection_can_change_qty' => 11, 'delete' => '']]];
$selection = $this->getMock('Magento\\Bundle\\Model\\Selection', ['getProductId', 'getPosition', 'getIsDefault', 'getSelectionPriceType', 'getSelectionPriceValue', 'getSelectionQty', 'getSelectionCanChangeQty', '__wakeup'], [], '', false);
$selections = [$selection];
$selectionCollection = $this->getMock('Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', [], [], '', false);
// method flow
$this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle'));
$this->product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($instance));
$instance->expects($this->once())->method('setStoreFilter')->with(null, $this->product);
$instance->expects($this->once())->method('getOptionsCollection')->with($this->product)->will($this->returnValue($optionCollection));
$instance->expects($this->once())->method('getSelectionsCollection')->with(null, $this->product)->will($this->returnValue($selectionCollection));
$optionCollection->expects($this->once())->method('appendSelections')->with($selectionCollection);
$option->expects($this->any())->method('getSelections')->will($this->returnValue($selections));
$option->expects($this->at(0))->method('getData')->with('required')->will($this->returnValue(true));
$option->expects($this->at(1))->method('getData')->with('position')->will($this->returnValue(100));
$option->expects($this->at(2))->method('getData')->with('type')->will($this->returnValue('someType'));
$option->expects($this->at(3))->method('getData')->with('title')->will($this->returnValue('title'));
$option->expects($this->at(4))->method('getData')->with('title')->will($this->returnValue('title'));
$selection->expects($this->once())->method('getProductId')->will($this->returnValue(123));
$selection->expects($this->once())->method('getPosition')->will($this->returnValue(500));
$selection->expects($this->once())->method('getIsDefault')->will($this->returnValue(false));
$selection->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue('priceType'));
$selection->expects($this->once())->method('getSelectionPriceValue')->will($this->returnValue('priceVal'));
$selection->expects($this->once())->method('getSelectionQty')->will($this->returnValue(21));
$selection->expects($this->once())->method('getSelectionCanChangeQty')->will($this->returnValue(11));
$this->duplicate->expects($this->once())->method('setBundleOptionsData')->with($optionRawData);
$this->duplicate->expects($this->once())->method('setBundleSelectionsData')->with($selectionRawData);
$this->model->build($this->product, $this->duplicate);
}
示例8: testGetSwatchesByOptionsIdIf3
public function testGetSwatchesByOptionsIdIf3()
{
$swatchMock = $this->getMock('\\Magento\\Swatches\\Model\\Swatch', [], [], '', false);
$optionsData = ['type' => 0, 'store_id' => 0, 'value' => 'test_test', 'option_id' => 35, 'id' => 423];
$swatchMock->expects($this->at(0))->method('offsetGet')->with('type')->willReturn(0);
$swatchMock->expects($this->at(1))->method('offsetGet')->with('store_id')->willReturn(0);
$swatchMock->expects($this->at(2))->method('offsetGet')->with('store_id')->willReturn(0);
$swatchMock->expects($this->at(3))->method('offsetGet')->with('option_id')->willReturn(35);
$swatchMock->expects($this->at(4))->method('getData')->with('')->willReturn($optionsData);
$swatchCollectionMock = $this->objectManager->getCollectionMock('\\Magento\\Swatches\\Model\\ResourceModel\\Swatch\\Collection', [$swatchMock]);
$this->swatchCollectionFactoryMock->method('create')->willReturn($swatchCollectionMock);
$swatchCollectionMock->method('addFilterByOptionsIds')->with([35])->will($this->returnSelf());
$storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
$this->storeManagerMock->method('getStore')->willReturn($storeMock);
$storeMock->method('getId')->willReturn(1);
$this->swatchHelperObject->getSwatchesByOptionsId([35]);
}
示例9: testGetListWhenFilterGroupExists
public function testGetListWhenFilterGroupExists()
{
$searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaInterface');
$filterGroupMock = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
$searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock]));
$filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterMock]);
$filterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('like');
$filterMock->expects($this->once())->method('getField')->willReturn('region_name');
$filterMock->expects($this->once())->method('getValue')->willReturn('condition_value');
$objectManager = new ObjectManager($this);
$rateMock = $this->getTaxRateMock([]);
$items = [$rateMock];
$collectionMock = $objectManager->getCollectionMock('Magento\\Tax\\Model\\ResourceModel\\Calculation\\Rate\\Collection', $items);
$collectionMock->expects($this->once())->method('addFieldToFilter')->with(['region_table.code'], [['like' => 'condition_value']]);
$sortOrderMock = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false);
$searchCriteriaMock->expects($this->any())->method('getSortOrders')->will($this->returnValue([$sortOrderMock]));
$sortOrderMock->expects($this->once())->method('getField')->willReturn('field_name');
$sortOrderMock->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);
$collectionMock->expects($this->once())->method('addOrder')->with('main_table.field_name', 'ASC');
$currentPage = 1;
$pageSize = 100;
$searchCriteriaMock->expects($this->any())->method('getCurrentPage')->will($this->returnValue($currentPage));
$searchCriteriaMock->expects($this->any())->method('getPageSize')->will($this->returnValue($pageSize));
$rateMock = $this->getTaxRateMock([]);
$collectionMock->expects($this->once())->method('joinRegionTable');
$collectionMock->expects($this->once())->method('setCurPage')->with($currentPage);
$collectionMock->expects($this->once())->method('setPageSize')->with($pageSize);
$collectionMock->expects($this->once())->method('getSize')->will($this->returnValue(count($items)));
$this->rateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rateMock));
$rateMock->expects($this->any())->method('getCollection')->will($this->returnValue($collectionMock));
$this->searchResultMock->expects($this->once())->method('setItems')->with($items)->willReturnSelf();
$this->searchResultMock->expects($this->once())->method('setTotalCount')->with(count($items))->willReturnSelf();
$this->searchResultMock->expects($this->once())->method('setSearchCriteria')->with($searchCriteriaMock)->willReturnSelf();
$this->searchResultFactory->expects($this->once())->method('create')->willReturn($this->searchResultMock);
$this->joinProcessorMock->expects($this->once())->method('process')->with($collectionMock);
$this->model->getList($searchCriteriaMock);
}