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]); }
protected function setUp() { $this->coreEntityFactoryMock = $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', [], [], '', false); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false); $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $this->coreResourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceHelperMock = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Helper', [], [], '', false); $this->validatorFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false); $this->entityFactoryMock = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false); /** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */ $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->statementMock = $this->getMock('Magento\\Framework\\DB\\Statement\\Pdo\\Mysql', ['fetch'], [], '', false); /** @var $selectMock \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */ $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $this->coreEntityFactoryMock->expects($this->any())->method('create')->will($this->returnCallback([$this, 'getMagentoObject'])); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $connectionMock->expects($this->any())->method('query')->willReturn($this->statementMock); $this->coreResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); $entityMock = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false); $entityMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); $entityMock->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([])); $this->validatorFactoryMock->expects($this->any())->method('create')->with('test_entity_model')->will($this->returnValue($entityMock)); $this->model = new AbstractCollectionStub($this->coreEntityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->configMock, $this->coreResourceMock, $this->entityFactoryMock, $this->resourceHelperMock, $this->validatorFactoryMock, null); }
/** * @param boolean $cacheEnabled * @param int $loadCalls * @param string $cachedValue * @param array $factoryCalls * @dataProvider getAttributeCacheDataProvider * @return void */ public function testGetAttributeCache($cacheEnabled, $loadCalls, $cachedValue, $factoryCalls) { $this->stateMock->expects($this->atLeastOnce())->method('isEnabled')->with(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER)->willReturn($cacheEnabled); $this->cacheMock->expects($this->exactly($loadCalls))->method('load')->with(Config::ATTRIBUTES_CACHE_ID)->willReturn($cachedValue); $collectionStub = new Object([['entity_type_code' => 'type_code_1', 'entity_type_id' => 1]]); $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($collectionStub); $this->typeFactoryMock->expects($this->any())->method('create')->willReturn(new Object(['id' => 101])); $this->universalFactoryMock->expects($this->exactly(count($factoryCalls)))->method('create')->will($this->returnValueMap($factoryCalls)); $entityType = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Type')->setMethods(['getEntity'])->disableOriginalConstructor()->getMock(); $this->config->getAttribute($entityType, 'attribute_code_1'); }
public function setUp() { $this->coreEntityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', array(), array(), '', false); $this->loggerMock = $this->getMock('Magento\\Framework\\Logger', array(), array(), '', false); $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface', array(), array(), '', false); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', array(), array(), '', false); $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', array(), array(), '', false); $this->coreResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', array('getConnection'), array(), '', false); $this->resourceHelperMock = $this->getMock('Magento\\Eav\\Model\\Resource\\Helper', array(), array(), '', false); $this->validatorFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', array(), array(), '', false); $this->entityFactoryMock = $this->getMock('Magento\\Eav\\Model\\EntityFactory', array(), array(), '', false); /** @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject */ $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', array(), array(), '', false); /** @var $selectMock \Zend_Db_Select|\PHPUnit_Framework_MockObject_MockObject */ $selectMock = $this->getMock('Zend_Db_Select', array(), array(), '', false); $this->coreEntityFactoryMock->expects($this->any())->method('create')->will($this->returnCallback(array($this, 'getMagentoObject'))); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $this->coreResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); $entityMock = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', array(), array(), '', false); $entityMock->expects($this->once())->method('getReadConnection')->will($this->returnValue($connectionMock)); $entityMock->expects($this->once())->method('getDefaultAttributes')->will($this->returnValue(array())); $this->validatorFactoryMock->expects($this->once())->method('create')->with('test_entity_model')->will($this->returnValue($entityMock)); $this->model = new \Magento\Eav\Model\Entity\Collection\AbstractCollectionStub($this->coreEntityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->configMock, $this->coreResourceMock, $this->entityFactoryMock, $this->resourceHelperMock, $this->validatorFactoryMock, null); }