當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::setConnection方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\ResourceModel\Product\Collection::setConnection方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::setConnection方法的具體用法?PHP Collection::setConnection怎麽用?PHP Collection::setConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\ResourceModel\Product\Collection的用法示例。


在下文中一共展示了Collection::setConnection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function setUp()
 {
     $entityFactory = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $fetchStrategy = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $eventManager = $this->getMockBuilder('Magento\\Framework\\Event\\ManagerInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $eavConfig = $this->getMockBuilder('Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->getMock();
     $resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $eavEntityFactory = $this->getMockBuilder('Magento\\Eav\\Model\\EntityFactory')->disableOriginalConstructor()->getMock();
     $resourceHelper = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Helper')->disableOriginalConstructor()->getMock();
     $universalFactory = $this->getMockBuilder('Magento\\Framework\\Validator\\UniversalFactory')->disableOriginalConstructor()->getMock();
     $storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods(['getStore', 'getId'])->getMockForAbstractClass();
     $moduleManager = $this->getMockBuilder('Magento\\Framework\\Module\\Manager')->disableOriginalConstructor()->getMock();
     $catalogProductFlatState = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State')->disableOriginalConstructor()->getMock();
     $scopeConfig = $this->getMockBuilder('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $productOptionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\OptionFactory')->disableOriginalConstructor()->getMock();
     $catalogUrl = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Url')->disableOriginalConstructor()->getMock();
     $localeDate = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->disableOriginalConstructor()->getMock();
     $dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->getMock();
     $groupManagement = $this->getMockBuilder('Magento\\Customer\\Api\\GroupManagementInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $entityMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\AbstractEntity')->disableOriginalConstructor()->getMock();
     $storeManager->expects($this->any())->method('getId')->willReturn(1);
     $storeManager->expects($this->any())->method('getStore')->willReturnSelf();
     $universalFactory->expects($this->exactly(1))->method('create')->willReturnOnConsecutiveCalls($entityMock);
     $entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
     $entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([]);
     $entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);
     $helper = new ObjectManager($this);
     $this->collection = $helper->getObject('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['entityFactory' => $entityFactory, 'logger' => $logger, 'fetchStrategy' => $fetchStrategy, 'eventManager' => $eventManager, 'eavConfig' => $eavConfig, 'resource' => $resource, 'eavEntityFactory' => $eavEntityFactory, 'resourceHelper' => $resourceHelper, 'universalFactory' => $universalFactory, 'storeManager' => $storeManager, 'moduleManager' => $moduleManager, 'catalogProductFlatState' => $catalogProductFlatState, 'scopeConfig' => $scopeConfig, 'productOptionFactory' => $productOptionFactory, 'catalogUrl' => $catalogUrl, 'localeDate' => $localeDate, 'customerSession' => $customerSession, 'dateTime' => $dateTime, 'groupManagement' => $groupManagement, 'connection' => $this->connectionMock]);
     $this->collection->setConnection($this->connectionMock);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:38,代碼來源:CollectionTest.php


注:本文中的Magento\Catalog\Model\ResourceModel\Product\Collection::setConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。