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


PHP MetadataPool::expects方法代码示例

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


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

示例1: testExecute

 public function testExecute()
 {
     $entityId = 1;
     $linkId = 2;
     $oldStore = 1;
     $newStore = 2;
     $linkField = 'link_id';
     $adapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMockForAbstractClass();
     $whereForDelete = [$linkField . ' = ?' => $linkId, 'store_id IN (?)' => [$oldStore]];
     $adapter->expects($this->once())->method('delete')->with('cms_page_store', $whereForDelete)->willReturnSelf();
     $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore];
     $adapter->expects($this->once())->method('insertMultiple')->with('cms_page_store', [$whereForInsert])->willReturnSelf();
     $entityMetadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->once())->method('getEntityConnection')->willReturn($adapter);
     $entityMetadata->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $this->metadataPool->expects($this->once())->method('getMetadata')->with('Magento\\Cms\\Model\\Page')->willReturn($entityMetadata);
     $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]);
     $this->resourcePage->expects($this->once())->method('getTable')->with('cms_page_store')->willReturn('cms_page_store');
     $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->setMethods(['getStores', 'getStoreId', 'getId', 'getData'])->getMock();
     $page->expects($this->once())->method('getStores')->willReturn(null);
     $page->expects($this->once())->method('getStoreId')->willReturn($newStore);
     $page->expects($this->once())->method('getId')->willReturn($entityId);
     $page->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId);
     $result = $this->model->execute('Magento\\Cms\\Model\\Page', $page);
     $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:26,代码来源:SaveHandlerTest.php

示例2: setUp

 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select', 'fetchOne'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['reset', 'from', 'join', 'where', 'group', 'limit'])->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock->expects(self::once())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->getMetaDataMock());
     $this->model = $helper->getObject('Magento\\ConfigurableProduct\\Model\\Attribute\\LockValidator', ['resource' => $this->resource, 'metadataPool' => $this->metadataPoolMock]);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:LockValidatorTest.php

示例3: setUp

 protected function setUp()
 {
     $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false, false, true, []);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $metadata->expects($this->any())->method('getEntityTable')->willReturn('entity_table');
     $metadata->expects($this->any())->method('getEntityConnection')->willReturn($this->connection);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($metadata);
     $this->subject = new \Magento\Framework\Model\ResourceModel\Db\DeleteEntityRow($this->metadataPool);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:11,代码来源:DeleteEntityRowTest.php

示例4: setUp

 protected function setUp()
 {
     $connectionMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->relation = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Relation', [], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($metadata);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable', ['resource' => $this->resource, 'catalogProductRelation' => $this->relation, 'metadataPool' => $this->metadataPool]);
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:ConfigurableTest.php

示例5: testExecuteWithString

 public function testExecuteWithString()
 {
     $customers = '1,2';
     $websites = '3,4,5';
     $entityData = ['row_id' => 1, 'rule_id' => 1, 'website_ids' => $websites, 'customer_group_ids' => $customers];
     $className = '\\Magento\\Framework\\Model\\Entity\\EntityMetadata';
     $metadata = $this->getMock($className, [], [], '', false);
     $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id');
     $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata);
     $this->ruleResource->expects($this->any())->method('bindRuleToEntity')->withConsecutive([1, [3, 4, 5]], [1, [1, 2]]);
     $result = $this->model->execute(RuleInterface::class, $entityData);
     $this->assertEquals($entityData, $result);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:13,代码来源:SaveHandlerTest.php

示例6: setUp

 protected function setUp()
 {
     $this->metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $this->metadata->expects($this->any())->method('getIdentifierField')->willReturn('identifier');
     $this->hydrator = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityHydrator', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getHydrator')->with('Test\\Entity\\Type')->willReturn($this->hydrator);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($this->metadata);
     $this->abstractEntity = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], '', false, false, true, []);
     $this->writeOperation = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Operation\\WriteInterface', [], '', false, false, true, []);
     $this->orchestratorPool = $this->getMock('Magento\\Framework\\Model\\OrchestratorPool', [], [], '', false);
     $this->subject = new \Magento\Framework\Model\EntityManager($this->orchestratorPool, $this->metadataPool);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:13,代码来源:EntityManagerTest.php

示例7: testExecute

 /**
  * test Execute
  */
 public function testExecute()
 {
     $entityData = ['row_id' => 2, 'rule_id' => 1];
     $customers = [1, 2];
     $websites = [3, 4, 5];
     $className = '\\Magento\\Framework\\Model\\Entity\\EntityMetadata';
     $metadata = $this->getMock($className, [], [], '', false);
     $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id');
     $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata);
     $this->ruleResource->expects($this->once())->method('getCustomerGroupIds')->willReturn($customers);
     $this->ruleResource->expects($this->once())->method('getWebsiteIds')->willReturn($websites);
     $result = $this->model->execute(RuleInterface::class, $entityData);
     $expected = ['row_id' => 2, 'rule_id' => 1, 'customer_group_ids' => [1, 2], 'website_ids' => [3, 4, 5]];
     $this->assertEquals($expected, $result);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:18,代码来源:ReadHandlerTest.php

示例8: testExecute

 /**
  * @param string $entityType
  * @param array $entity
  * @param string $identifier
  * @param string $linkField
  * @dataProvider executeParameters
  */
 public function testExecute($entityType, $entity, $identifier, $linkField)
 {
     $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($entityType)->willReturn($this->metadataMock);
     $entityWithMainRead = array_merge($entity, ['main_read' => 'some info']);
     $this->readMainMock->expects($this->once())->method('execute')->with($entityType, $entity, $identifier)->willReturn($entityWithMainRead);
     $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $entityWithExtensionAndRelation = $entityWithMainRead;
     if (isset($entity[$linkField])) {
         $entityWithExtension = array_merge($entityWithMainRead, ['ext' => 'extParameter']);
         $this->readExtensionMock->expects($this->once())->method('execute')->with($entityType, $entityWithMainRead)->willReturn($entityWithExtension);
         $entityWithExtensionAndRelation = array_merge($entityWithExtension, ['relation' => 'some_relation']);
         $this->readRelationMock->expects($this->once())->method('execute')->with($entityType, $entityWithExtension)->willReturn($entityWithExtensionAndRelation);
     }
     $this->assertEquals($entityWithExtensionAndRelation, $this->read->execute($entityType, $entity, $identifier));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:22,代码来源:ReadTest.php

示例9: setUp

 protected function setUp()
 {
     $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock();
     $this->resource = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->relation = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product\Relation::class, [], [], '', false);
     $this->metadataMock = $this->getMock(\Magento\Framework\Model\Entity\EntityMetadata::class, [], [], '', false);
     $this->metadataPoolMock = $this->getMock(\Magento\Framework\Model\Entity\MetadataPool::class, [], [], '', false);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->metadataMock);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->configurable = $this->objectManagerHelper->getObject(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class, ['resource' => $this->resource, 'catalogProductRelation' => $this->relation]);
     $reflection = new \ReflectionClass(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class);
     $reflectionProperty = $reflection->getProperty('metadataPool');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->configurable, $this->metadataPoolMock);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:16,代码来源:ConfigurableTest.php

示例10: setUp

 protected function setUp()
 {
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->repositoryMock = $this->getMock('\\Magento\\Catalog\\Api\\ProductRepositoryInterface', [], [], '', false);
     $this->productTypeMock = $this->getMock('\\Magento\\Downloadable\\Model\\Product\\Type', [], [], '', false);
     $this->linkResourceMock = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\Link', [], [], '', false);
     $this->contentValidatorMock = $this->getMock('\\Magento\\Downloadable\\Model\\Link\\ContentValidator', [], [], '', false);
     $this->contentUploaderMock = $this->getMock('Magento\\Downloadable\\Helper\\File', [], [], '', false);
     $this->jsonEncoderMock = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false);
     $this->linkFactoryMock = $this->getMockBuilder('Magento\\Downloadable\\Api\\Data\\LinkInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['__wakeup', 'getTypeId', 'setDownloadableData', 'save', 'getId', 'getStoreId', 'getStore', 'getWebsiteIds', 'getData'], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->service = new \Magento\Downloadable\Model\LinkRepository($this->metadataPoolMock, $this->repositoryMock, $this->productTypeMock, $this->linkResourceMock, $this->linkFactoryMock, $this->contentValidatorMock, $this->jsonEncoderMock, $this->contentUploaderMock);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:16,代码来源:LinkRepositoryTest.php

示例11: setUp

 protected function setUp()
 {
     $this->categoryFactoryMock = $this->getMock('\\Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false);
     $this->categoryResourceMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category', [], [], '', false);
     $this->storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['getId'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->extensibleDataObjectConverterMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\ExtensibleDataObjectConverter')->setMethods(['toNestedArray'])->disableOriginalConstructor()->getMock();
     $metadataMock = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadataMock->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\CategoryInterface::class)->willReturn($metadataMock);
     $this->model = new \Magento\Catalog\Model\CategoryRepository($this->categoryFactoryMock, $this->categoryResourceMock, $this->storeManagerMock, $this->metadataPoolMock);
     // Todo: \Magento\Framework\TestFramework\Unit\Helper\ObjectManager to do this automatically (MAGETWO-49793)
     $reflection = new \ReflectionClass(get_class($this->model));
     $reflectionProperty = $reflection->getProperty('extensibleDataObjectConverter');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->model, $this->extensibleDataObjectConverterMock);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:19,代码来源:CategoryRepositoryTest.php

示例12: setUp

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $fileStorageDbMock = $this->getMock('Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false);
     $filesystem = $this->getMockBuilder('Magento\\Framework\\Filesystem')->disableOriginalConstructor()->getMock();
     $coreRegistry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $logger = $this->getMockBuilder('\\Psr\\Log\\LoggerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     $this->_typeConfigurableFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\ConfigurableFactory', ['create', 'saveProducts'], [], '', false);
     $this->_configurableAttributeFactoryMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\AttributeFactory', ['create'], [], '', false);
     $this->_productCollectionFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->_attributeCollectionFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->productRepository = $this->getMock('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $this->extensionAttributesJoinProcessorMock = $this->getMock('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface', [], [], '', false);
     $this->entityMetadata = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
     $this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->entityMetadata);
     $this->cache = $this->getMockBuilder(\Magento\Framework\Cache\FrontendInterface::class)->getMockForAbstractClass();
     $this->_model = $this->_objectHelper->getObject('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', ['typeConfigurableFactory' => $this->_typeConfigurableFactory, 'configurableAttributeFactory' => $this->_configurableAttributeFactoryMock, 'productCollectionFactory' => $this->_productCollectionFactory, 'attributeCollectionFactory' => $this->_attributeCollectionFactory, 'eventManager' => $eventManager, 'fileStorageDb' => $fileStorageDbMock, 'filesystem' => $filesystem, 'coreRegistry' => $coreRegistry, 'logger' => $logger, 'productRepository' => $this->productRepository, 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock, 'cache' => $this->cache, 'metadataPool' => $this->metadataPool]);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:23,代码来源:ConfigurableTest.php

示例13: setUp

 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false);
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\Manager', [], [], '', false);
     $this->optionsFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Value\\CollectionFactory', ['create'], [], '', false);
     $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $this->joinProcessor = $this->getMockBuilder('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->resourceMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option', ['getConnection', '__wakeup', 'getMainTable', 'getTable'], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'reset', 'join'], [], '', false);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select'], [], '', false);
     $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resourceMock->expects($this->once())->method('getMainTable')->will($this->returnValue('test_main_table'));
     $this->resourceMock->expects($this->exactly(3))->method('getTable')->withConsecutive(['test_main_table'], ['catalog_product_entity'], ['catalog_product_entity'])->willReturnOnConsecutiveCalls($this->returnValue('test_main_table'), 'catalog_product_entity', 'catalog_product_entity');
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->selectMock->expects($this->exactly(2))->method('join');
     $this->collection = new Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->optionsFactoryMock, $this->storeManagerMock, $this->metadataPoolMock, $this->joinProcessor, null, $this->resourceMock);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:23,代码来源:CollectionTest.php

示例14: setUp

 /**
  * Set up test
  *
  * @return void
  */
 protected function setUp()
 {
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\ResourceModel\\Rule\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
     $this->backend = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $metadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->db = $this->getMock('Zend_Db_Statement_Interface', [], [], '', false);
     $this->website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', [], [], '', false);
     $this->rules = $this->getMock('Magento\\CatalogRule\\Model\\Rule', [], [], '', false);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false);
     $this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->dateFormat = $this->getMock('Magento\\Framework\\Stdlib\\DateTime', [], [], '', false);
     $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTime', [], [], '', false);
     $this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute'], [], '', false);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connection->expects($this->any())->method('query')->will($this->returnValue($this->db));
     $this->select->expects($this->any())->method('distinct')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('order')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$this->website]));
     $this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->rules->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->rules->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('getCustomerGroupIds')->will($this->returnValue([1]));
     $this->ruleCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
     $this->ruleCollectionFactory->expects($this->any())->method('addFieldToFilter')->will($this->returnValue([$this->rules]));
     $this->product->expects($this->any())->method('load')->will($this->returnSelf());
     $this->product->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->product->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('validate')->with($this->product)->willReturn(true);
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder($this->ruleCollectionFactory, $this->priceCurrency, $this->resource, $this->storeManager, $this->logger, $this->eavConfig, $this->dateFormat, $this->dateTime, $this->productFactory, $this->metadataPool);
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:51,代码来源:IndexBuilderTest.php

示例15: testAddCollectionData

 public function testAddCollectionData()
 {
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('join')->will($this->returnSelf());
     $select->expects($this->any())->method('joinInner')->will($this->returnSelf());
     $select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $connection->expects($this->any())->method('fetchCol')->will($this->returnValue([]));
     $resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $attributeConfig = $this->getMock('Magento\\Catalog\\Model\\Attribute\\Config', [], [], '', false);
     $attributes = ['attribute_one', 'attribute_two'];
     $attributeConfig->expects($this->once())->method('getAttributeNames')->with('catalog_category')->will($this->returnValue($attributes));
     $collection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false);
     $collection->expects($this->never())->method('getAllIds')->will($this->returnValue([]));
     $collection->expects($this->once())->method('getAllIdsSql')->will($this->returnValue($select));
     $collectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection\\Factory', [], [], '', false);
     $collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->any())->method('getId')->will($this->returnValue(1));
     $storeManager = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface');
     $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $categoryMetadataMock = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
     $categoryMetadataMock->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(CategoryInterface::class)->willReturn($categoryMetadataMock);
     $model = $objectHelper->getObject('Magento\\Catalog\\Model\\ResourceModel\\Category\\Tree', ['storeManager' => $storeManager, 'resource' => $resource, 'eventManager' => $eventManager, 'attributeConfig' => $attributeConfig, 'collectionFactory' => $collectionFactory, 'metadataPool' => $this->metadataPoolMock]);
     $nodeMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', ['getId', 'getPath'], [], '', false);
     $nodeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $nodeMock->expects($this->once())->method('getPath')->will($this->returnValue([]));
     $model->addNode($nodeMock);
     $this->assertSame($model, $model->addCollectionData(null, false, [], false, true));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:38,代码来源:TreeTest.php


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