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


PHP ObjectManager::getObject方法代碼示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->managerInterface = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->reviewFactory = $this->getMock('Magento\\Review\\Model\\ReviewFactory', ['create'], [], '', false);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rss = $this->objectManagerHelper->getObject('Magento\\Review\\Model\\Rss', ['eventManager' => $this->managerInterface, 'reviewFactory' => $this->reviewFactory]);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:7,代碼來源:RssTest.php

示例2: setUp

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $connection = $this->getMock('Zend_Db_Adapter_Pdo_Mysql', ['quote'], [], '', false);
     $connection->expects($this->any())->method('quote')->will($this->returnValue('\'TestProductName\''));
     $resource = $this->getMock('Magento\\Wishlist\\Model\\Resource\\Item', ['getReadConnection', 'getMainTable', 'getTableName', 'getTable'], [], '', false);
     $resource->expects($this->any())->method('getReadConnection')->will($this->returnValue($connection));
     $resource->expects($this->any())->method('getMainTable')->will($this->returnValue('testMainTableName'));
     $resource->expects($this->any())->method('getTableName')->will($this->returnValue('testMainTableName'));
     $resource->expects($this->any())->method('getTable')->will($this->returnValue('testMainTableName'));
     $catalogConfFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\ConfigFactory', ['create'], [], '', false);
     $catalogConf = $this->getMock('Magento\\Catalog\\Model\\Resource\\Config', ['getEntityTypeId'], [], '', false);
     $catalogConf->expects($this->once())->method('getEntityTypeId')->will($this->returnValue(4));
     $catalogConfFactory->expects($this->once())->method('create')->will($this->returnValue($catalogConf));
     $attribute = $this->getMock('Magento\\Catalog\\Model\\Entity\\Attribute', ['loadByCode', 'getBackendTable', 'getId'], [], '', false);
     $attribute->expects($this->once())->method('loadByCode')->with(4, 'name')->will($this->returnSelf());
     $attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue($this->attrTableName));
     $attribute->expects($this->once())->method('getId')->will($this->returnValue($this->attrId));
     $catalogAttrFactory = $this->getMock('Magento\\Catalog\\Model\\Entity\\AttributeFactory', ['create'], [], '', false);
     $catalogAttrFactory->expects($this->once())->method('create')->will($this->returnValue($attribute));
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getId'], [], '', false);
     $store->expects($this->once())->method('getId')->will($this->returnValue($this->storeId));
     $storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', ['getStore'], [], '', false);
     $storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->collection = $this->objectManager->getObject('Magento\\Wishlist\\Model\\Resource\\Item\\Collection', ['resource' => $resource, 'catalogConfFactory' => $catalogConfFactory, 'catalogAttrFactory' => $catalogAttrFactory, 'storeManager' => $storeManager]);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:29,代碼來源:CollectionTest.php

示例3: setUp

 /**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:36,代碼來源:RowCustomizerTest.php

示例4: setUp

 protected function setUp()
 {
     $this->configMock = $this->getMockBuilder('\\Magento\\Braintree\\Model\\Config\\PayPal')->disableOriginalConstructor()->getMock();
     $this->localResolverMock = $this->getMock('\\Magento\\Framework\\Locale\\ResolverInterface');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->model = $this->objectManagerHelper->getObject('Magento\\Braintree\\Model\\ConfigProvider\\PayPal', ['config' => $this->configMock, 'localeResolver' => $this->localResolverMock]);
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:7,代碼來源:PayPalTest.php

示例5: setUp

 public function setUp()
 {
     $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['getId', 'invalidate', 'getPriceIndexer', 'isScheduled'], [], '', false);
     $this->indexerRegistryMock = $this->getMock('Magento\\Framework\\Indexer\\IndexerRegistry', ['get'], [], '', false);
     $this->_model = $this->_objectManager->getObject('Magento\\CatalogImportExport\\Model\\Indexer\\Product\\Price\\Plugin\\Import', ['indexerRegistry' => $this->indexerRegistryMock]);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:7,代碼來源:ImportTest.php

示例6: setUp

 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->managerInterfaceMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->resourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->entityFactoryMock2 = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false);
     $this->helperMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Helper', [], [], '', false);
     $entity = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false);
     $entity->expects($this->any())->method('getReadConnection')->will($this->returnValue($adapter));
     $entity->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
     $this->universalFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false);
     $this->universalFactoryMock->expects($this->any())->method('create')->will($this->returnValue($entity));
     $this->storeManagerMock = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnCallback(function ($store) {
         return is_object($store) ? $store : new \Magento\Framework\Object(['id' => 42]);
     }));
     $this->catalogHelperMock = $this->getMock('Magento\\Catalog\\Helper\\Data', [], [], '', false);
     $this->stateMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\State', [], [], '', false);
     $this->scopeConfigInterfaceMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->optionFactoryMock = $this->getMock('Magento\\Catalog\\Model\\Product\\OptionFactory', [], [], '', false);
     $this->urlMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Url', [], [], '', false);
     $this->timezoneInterfaceMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->sessionMock = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->dateTimeMock = $this->getMock('Magento\\Framework\\Stdlib\\DateTime');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->collection = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Resource\\Product\\Link\\Product\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->managerInterfaceMock, 'eavConfig' => $this->configMock, 'resource' => $this->resourceMock, 'eavEntityFactory' => $this->entityFactoryMock2, 'resourceHelper' => $this->helperMock, 'universalFactory' => $this->universalFactoryMock, 'storeManager' => $this->storeManagerMock, 'catalogData' => $this->catalogHelperMock, 'catalogProductFlatState' => $this->stateMock, 'scopeConfig' => $this->scopeConfigInterfaceMock, 'productOptionFactory' => $this->optionFactoryMock, 'catalogUrl' => $this->urlMock, 'localeDate' => $this->timezoneInterfaceMock, 'customerSession' => $this->sessionMock, 'dateTime' => $this->dateTimeMock]);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:31,代碼來源:CollectionTest.php

示例7: setUp

 /**
  * Set up helper.
  */
 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $typeProcessor = $this->objectManager->getObject('Magento\\Framework\\Reflection\\TypeProcessor');
     $objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock();
     $classReflection = $this->getMock('Magento\\Webapi\\Model\\Config\\ClassReflector', ['reflectClassMethods'], ['_typeProcessor' => $typeProcessor], '');
     $classReflection->expects($this->any())->method('reflectClassMethods')->will($this->returnValue([]));
     $servicesConfig = ['services' => ['Magento\\Customer\\Api\\AccountManagementInterface' => ['V1' => ['methods' => ['activate' => ['resources' => [['Magento_Customer::manage']], 'secure' => false]]]], 'Magento\\Customer\\Api\\CustomerRepositoryInterface' => ['V1' => ['methods' => ['getById' => ['resources' => [['Magento_Customer::customer']], 'secure' => false]]]]]];
     /**
      * @var $registryMock \Magento\Framework\Registry
      */
     $registryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock();
     /**
      * @var $cacheMock \Magento\Framework\App\Cache\Type\Webapi
      */
     $cacheMock = $this->getMockBuilder('Magento\\Framework\\App\\Cache\\Type\\Webapi')->disableOriginalConstructor()->getMock();
     /** @var $readerMock \Magento\Webapi\Model\Config\Reader */
     $readerMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Config\\Reader')->disableOriginalConstructor()->getMock();
     $readerMock->expects($this->any())->method('read')->will($this->returnValue($servicesConfig));
     /** @var $config \Magento\Webapi\Model\Config */
     $config = new \Magento\Webapi\Model\Config($cacheMock, $readerMock);
     /** @var $config \Magento\Webapi\Model\ServiceMetadata */
     $serviceMetadata = new \Magento\Webapi\Model\ServiceMetadata($config, $cacheMock, $classReflection, $typeProcessor);
     $this->_soapConfig = $this->objectManager->getObject('Magento\\Webapi\\Model\\Soap\\Config', ['objectManager' => $objectManagerMock, 'registry' => $registryMock, 'serviceMetadata' => $serviceMetadata]);
     parent::setUp();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:29,代碼來源:ConfigTest.php

示例8: setUp

 protected function setUp()
 {
     $this->objectManager = new ObjectManagerHelper($this);
     $this->dataProviderMock = $this->getMockBuilder(ModifierInterface::class)->getMockForAbstractClass();
     $this->objectManagerMock = $this->getMockBuilder(ObjectManager::class)->disableOriginalConstructor()->getMock();
     $this->model = $this->objectManager->getObject(\Magento\Ui\DataProvider\Modifier\ModifierFactory::class, ['objectManager' => $this->objectManagerMock]);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:7,代碼來源:FactoryTest.php

示例9: setUp

 protected function setUp()
 {
     $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->pageFactory = $this->objectManagerHelper->getObject('Magento\\Framework\\View\\Result\\PageFactory', ['objectManager' => $this->objectManagerMock]);
     $this->page = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:7,代碼來源:PageFactoryTest.php

示例10: getModel

 /**
  * @return AbstractElement
  */
 protected function getModel()
 {
     if (null === $this->model) {
         $this->model = $this->objectManager->getObject($this->getModelName(), ['context' => $this->contextMock]);
     }
     return $this->model;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:10,代碼來源:AbstractElementTest.php

示例11: setUp

 /**
  * Setup the test
  */
 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->customerRegistry = $this->getMock(\Magento\Customer\Model\CustomerRegistry::class, [], [], '', false);
     $this->customerResourceModel = $this->getMock(\Magento\Customer\Model\ResourceModel\Customer::class, [], [], '', false);
     $this->model = $this->objectManager->getObject(\Magento\Customer\Model\CustomerAuthUpdate::class, ['customerRegistry' => $this->customerRegistry, 'customerResourceModel' => $this->customerResourceModel]);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:10,代碼來源:CustomerAuthUpdateTest.php

示例12: setUp

 public function setUp()
 {
     $context = $this->getMock('Magento\\Backend\\Block\\Template\\Context', [], [], '', false);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $context->expects($this->once())->method('getEventManager')->will($this->returnValue($eventManager));
     $scopeConfig = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false);
     $context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', ['getStores', 'getDefaultStoreView'], [], '', false);
     $context->expects($this->once())->method('getStoreManager')->will($this->returnValue($this->storeManager));
     $appState = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false);
     $context->expects($this->once())->method('getAppState')->will($this->returnValue($appState));
     $templateFactory = $this->getMock('Magento\\Newsletter\\Model\\TemplateFactory', ['create'], [], '', false);
     $this->template = $this->getMock('Magento\\Newsletter\\Model\\Template', [], [], '', false);
     $templateFactory->expects($this->once())->method('create')->will($this->returnValue($this->template));
     $subscriberFactory = $this->getMock('Magento\\Newsletter\\Model\\SubscriberFactory', ['create'], [], '', false);
     $this->subscriber = $this->getMock('Magento\\Newsletter\\Model\\Subscriber', [], [], '', false);
     $subscriberFactory->expects($this->once())->method('create')->will($this->returnValue($this->subscriber));
     $queueFactory = $this->getMock('Magento\\Newsletter\\Model\\QueueFactory', ['create'], [], '', false);
     $this->queue = $this->getMock('Magento\\Newsletter\\Model\\Queue', ['load'], [], '', false);
     $queueFactory->expects($this->any())->method('create')->will($this->returnValue($this->queue));
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->preview = $this->objectManager->getObject('Magento\\Newsletter\\Block\\Adminhtml\\Queue\\Preview', ['context' => $context, 'templateFactory' => $templateFactory, 'subscriberFactory' => $subscriberFactory, 'queueFactory' => $queueFactory]);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:25,代碼來源:PreviewTest.php

示例13: setUp

 protected function setUp()
 {
     $this->configMock = $this->getMockBuilder('\\Magento\\Braintree\\Model\\Config\\Cc')->disableOriginalConstructor()->getMock();
     $this->transactionFactoryMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\TransactionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->processBraintreePaymentObserver = $this->objectManagerHelper->getObject('Magento\\Braintree\\Observer\\ProcessBraintreePayment', ['config' => $this->configMock, 'transactionFactory' => $this->transactionFactoryMock]);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:7,代碼來源:ProcessBraintreePaymentTest.php

示例14: setUp

 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManager($this);
     /** @var Context $context */
     $this->context = $this->objectManagerHelper->getObject('Magento\\Framework\\View\\Element\\Template\\Context');
     $this->block = new Links($this->context);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:7,代碼來源:LinksTest.php

示例15: testGetProperties

 /**
  * @dataProvider getPropertiesDataProvider
  */
 public function testGetProperties($queryText, $resultsCount)
 {
     /** @var \Magento\Search\Model\QueryResult $queryResult */
     $queryResult = $this->objectManager->getObject('Magento\\Search\\Model\\QueryResult', ['queryText' => $queryText, 'resultsCount' => $resultsCount]);
     $this->assertEquals($queryText, $queryResult->getQueryText());
     $this->assertEquals($resultsCount, $queryResult->getResultsCount());
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:10,代碼來源:QueryResultTest.php


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