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); }
/** * @return void */ public function testDeleteRecordsOlderThen() { $timestamp = 12345; $this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->dbAdapterMock); $this->dbAdapterMock->expects($this->once())->method('delete')->with($this->model->getMainTable(), ['created_at < ?' => $this->dateTimeMock->formatDate($timestamp)])->willReturnSelf(); $this->assertEquals($this->model, $this->model->deleteRecordsOlderThen($timestamp)); }
protected function setUp() { parent::setUp(); $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false); $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false); $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection)); $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([])); $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false); $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf()); $this->attrCollectionFactory->expects($this->any())->method('addFieldToFilter')->willReturn([]); $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getErrorAggregator', 'getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope'], [], '', false); $this->entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject()); $this->params = [0 => $this->entityModel, 1 => 'grouped']; $this->links = $this->getMock('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped\\Links', [], [], '', false); $entityAttributes = [['attribute_set_name' => 'attribute_id', 'attribute_id' => 'attributeSetName']]; $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false); $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false); $this->select->expects($this->any())->method('from')->will($this->returnSelf()); $this->select->expects($this->any())->method('where')->will($this->returnSelf()); $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf()); $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select)); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query')); $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock); $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf(); $this->connection->expects($this->any())->method('delete')->willReturnSelf(); $this->connection->expects($this->any())->method('quoteInto')->willReturn(''); $this->connection->expects($this->any())->method('fetchAll')->will($this->returnValue($entityAttributes)); $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false); $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection)); $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName')); $this->grouped = $this->objectManagerHelper->getObject('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'resource' => $this->resource, 'params' => $this->params, 'links' => $this->links]); }
protected function setUp() { $this->_adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface'); $this->_resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->_resourceMock->expects($this->any())->method('getConnection')->with('prefix')->will($this->returnValue($this->_adapterMock)); $this->_model = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Helper\\AbstractHelper', [$this->_resourceMock, 'prefix'], '', true, true, true, ['addLikeEscape']); }
protected function setUp() { parent::setUp(); $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getErrorAggregator', 'getBehavior', 'getNewSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope', 'getConnection'], [], '', false); $this->entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject()); $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto', 'fetchAssoc'], [], '', false); $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $this->select->expects($this->any())->method('from')->will($this->returnSelf()); $this->select->expects($this->any())->method('where')->will($this->returnSelf()); $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf()); $this->select->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select)); $this->initFetchAllCalls(); $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf(); $this->connection->expects($this->any())->method('delete')->willReturnSelf(); $this->connection->expects($this->any())->method('quoteInto')->willReturn(''); $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false); $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection)); $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName')); $this->attrSetColFac = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false); $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false); $this->attrSetColFac->expects($this->any())->method('create')->will($this->returnValue($this->setCollection)); $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([])); $this->prodAttrColFac = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false); $attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection', [], [], '', false); $attrCollection->expects($this->any())->method('addFieldToFilter')->willReturn([]); $this->prodAttrColFac->expects($this->any())->method('create')->will($this->returnValue($attrCollection)); $this->params = [0 => $this->entityModel, 1 => 'bundle']; $this->bundle = $this->objectManagerHelper->getObject('Magento\\BundleImportExport\\Model\\Import\\Product\\Type\\Bundle', ['attrSetColFac' => $this->attrSetColFac, 'prodAttrColFac' => $this->prodAttrColFac, 'resource' => $this->resource, 'params' => $this->params]); }
protected function setUp() { $objectManager = new ObjectManager($this); $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock(); $this->connection->expects($this->any())->method('quoteInto')->willReturnCallback(function ($query, $expression) { return str_replace('?', $expression, $query); }); $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resource->method('getTableName')->willReturnCallback(function ($table) { return 'prefix_' . $table; }); $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->website = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\WebsiteInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->website->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID); $this->store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->store->expects($this->any())->method('getId')->willReturn(self::STORE_ID); $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($this->website); $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store); $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock(); $attributeCollectionFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $attributeCollectionFactory->expects($this->once())->method('create')->willReturn($this->attributeCollection); $this->target = $objectManager->getObject('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper', ['resource' => $this->resource, 'storeManager' => $this->storeManager, 'attributeCollectionFactory' => $attributeCollectionFactory]); $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock(); $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMock(); }
/** * {@inheritDoc} */ protected function setUp() { $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->helper = new Helper($this->resourceMock); }
public function testCreate() { $triggerName = 'trigger_name'; $this->resourceMock->expects($this->atLeastOnce())->method('getTriggerName')->willReturn($triggerName); $triggerMock = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Trigger')->disableOriginalConstructor()->getMock(); $triggerMock->expects($this->exactly(3))->method('setName')->with($triggerName)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('triggerName')); $triggerMock->expects($this->exactly(3))->method('setTime')->with(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setEvent')->will($this->returnSelf()); $triggerMock->expects($this->exactly(3))->method('setTable')->with($this->tableName)->will($this->returnSelf()); $triggerMock->expects($this->exactly(6))->method('addStatement')->will($this->returnSelf()); $changelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []); $changelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('test_view_cl')); $changelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id')); $this->viewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($changelogMock)); $this->triggerFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($triggerMock)); $otherChangelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []); $otherChangelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('other_test_view_cl')); $otherChangelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id')); $otherViewMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ViewInterface', [], '', false, false, true, []); $otherViewMock->expects($this->exactly(1))->method('getId')->will($this->returnValue('other_id')); $otherViewMock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue([['name' => $this->tableName], ['name' => 'otherTableName']])); $otherViewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($otherChangelogMock)); $this->viewMock->expects($this->exactly(3))->method('getId')->will($this->returnValue('this_id')); $this->viewMock->expects($this->never())->method('getSubscriptions'); $this->viewCollectionMock->expects($this->exactly(1))->method('getViewsByStateMode')->with(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED)->will($this->returnValue([$this->viewMock, $otherViewMock])); $this->connectionMock->expects($this->exactly(3))->method('dropTrigger')->with('triggerName')->will($this->returnValue(true)); $this->connectionMock->expects($this->exactly(3))->method('createTrigger')->with($triggerMock); $this->model->create(); }
public function testSave() { $connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $resourceMock = $this->getMock('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', ['_construct', 'getConnection', '__wakeup', 'getIdFieldName'], [], '', false); $connectionInterfaceMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionInterfaceMock)); $data = 'tableName'; $this->resourcesMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); $this->resourcesMock->expects($this->any())->method('getTableName')->with($data)->will($this->returnValue('tableName')); $mainTableReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_mainTable'); $mainTableReflection->setAccessible(true); $mainTableReflection->setValue($this->model, 'tableName'); $idFieldNameReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_idFieldName'); $idFieldNameReflection->setAccessible(true); $idFieldNameReflection->setValue($this->model, 'idFieldName'); $connectionMock->expects($this->any())->method('save')->with('tableName', 'idFieldName'); $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName')); $abstractModelMock = $this->setupAbstractModel($resourceMock); $abstractModelMock->setIdFieldName('id'); $abstractModelMock->setData(['id' => 12345, 'name' => 'Test Name', 'value' => 'Test Value']); $abstractModelMock->afterLoad(); $this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData()); $newData = ['value' => 'Test Value New']; $abstractModelMock->addData($newData); $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData()); $abstractModelMock->isObjectNew(false); $connectionMock->expects($this->any())->method('update')->with('tableName', $newData, 'idFieldName'); $this->relationProcessorMock->expects($this->once())->method('validateDataIntegrity'); $this->entityManager->expects($this->once())->method('save'); $this->model->save($abstractModelMock); }
protected function setUp() { $this->config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['select', 'from', 'where', 'join'])->disableOriginalConstructor()->getMock(); $this->connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->storeViewService = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', ['eavConfig' => $this->config, 'resource' => $this->resource]); }
protected function setUp() { $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->setMethods(['getConnection'])->disableOriginalConstructor()->getMock(); $this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->connection); $this->indexScopeResolver = $this->getMockBuilder('\\Magento\\Framework\\Indexer\\ScopeResolver\\IndexScopeResolver')->setMethods(['resolve'])->disableOriginalConstructor()->getMock(); $objectManager = new ObjectManager($this); $this->target = $objectManager->getObject(\Magento\CatalogSearch\Model\Indexer\IndexStructure::class, ['resource' => $this->resource, 'indexScopeResolver' => $this->indexScopeResolver]); }
public function setUp() { $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $contextMock = $this->getMock('\\Magento\\Framework\\Model\\ModelResource\\Db\\Context', [], [], '', false); $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->tokenResource = new \Magento\Integration\Model\ResourceModel\Oauth\Token($contextMock, new \Magento\Framework\Stdlib\DateTime()); }
protected function setUp() { $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $contextMock = $this->getMock('\\Magento\\Framework\\Model\\ResourceModel\\Db\\Context', [], [], '', false); $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->nonceResource = new \Magento\Integration\Model\ResourceModel\Oauth\Nonce($contextMock); }
protected function setUp() { $this->config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $this->select = $this->getMock('Magento\\Framework\\Db\\Select', [], [], '', false); $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection)); $this->storeViewService = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', ['eavConfig' => $this->config, 'resource' => $this->resource]); }
public function testGetTable() { $tableName = 'table'; $expectedTableName = 'expected_table'; $this->resourceModel->expects($this->once())->method('getTableName')->with($tableName)->will($this->returnValue($expectedTableName)); $this->assertSame($expectedTableName, $this->object->getTable($tableName)); // Check that table name is cached $this->assertSame($expectedTableName, $this->object->getTable($tableName)); }
/** * Initialization */ protected function setUp() { $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock)); $this->appResourceMock->expects($this->any())->method('getTableName')->willReturnArgument(0); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->taxItem = $objectManager->getObject('Magento\\Sales\\Model\\ResourceModel\\Order\\Tax\\Item', ['resource' => $this->appResourceMock]); }
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); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable', ['resource' => $this->resource, 'catalogProductRelation' => $this->relation]); }
protected function setUp() { $this->connection = $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($this->connection)); $this->resource->expects($this->any())->method('getTableName')->willReturnArgument(0); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->attribute = $this->objectManagerHelper->getObject(Attribute::class, ['resource' => $this->resource]); }
/** * Test table name getter * * @return void */ public function testGetTableName() { $prefix = 'pre_'; $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($tableName) use($prefix) { return $prefix . $tableName; })); $this->assertEquals('pre_test_tmp', $this->_model->getTableName('test')); $this->_model->setUseIdxTable(true); $this->assertEquals('pre_test_idx', $this->_model->getTableName('test')); }
public function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $contextMock = $this->getMock('\\Magento\\Framework\\Model\\ResourceModel\\Db\\Context', [], [], '', false); $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->tokenResource = $objectManager->getObject('Magento\\Integration\\Model\\ResourceModel\\Oauth\\Token', ['context' => $contextMock]); }
protected function setUp() { $this->consumerMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Consumer', ['setUpdatedAt', 'getId'], [], '', false); $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $contextMock = $this->getMock('Magento\\Framework\\Model\\ResourceModel\\Db\\Context', [], [], '', false); $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->consumerResource = new \Magento\Integration\Model\ResourceModel\Oauth\Consumer($contextMock, new \Magento\Framework\Stdlib\DateTime()); }
public function testAddOrdersFilter() { $this->resourceConnectionMock->expects($this->exactly(2))->method('getConnection')->willReturn($this->connectionMock); $this->resourceConnectionMock->expects($this->once())->method('getTableName')->with('paypal_billing_agreement_order')->willReturn('pref_paypal_billing_agreement_order'); $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock); $this->selectMock->expects($this->once())->method('from')->with(['pbao' => 'pref_paypal_billing_agreement_order'], ['order_id'], null)->willReturnSelf(); $this->selectMock->expects($this->exactly(2))->method('where')->withConsecutive(['pbao.agreement_id IN(?)', [100]], ['main_table.entity_id IN (?)', [500]])->willReturnSelf(); $this->connectionMock->expects($this->once())->method('fetchCol')->with($this->selectMock, [])->willReturn([500]); $this->collectionMock->expects($this->once())->method('getSelect')->willReturn($this->selectMock); $this->assertEquals($this->agreementResource, $this->agreementResource->addOrdersFilter($this->collectionMock, 100)); }
protected function setUp() { $this->connectionAdapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select', 'dropTable'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionAdapter)); $this->request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->setMethods(['getQuery', 'getIndex', 'getSize'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->request->expects($this->exactly(2))->method('getIndex')->will($this->returnValue(self::INDEX_NAME)); $this->queryContainer = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Query\\QueryContainer')->setMethods(['addMatchQuery', 'getMatchQueries'])->disableOriginalConstructor()->getMock(); $this->queryContainer->expects($this->any())->method('addMatchQuery')->willReturnArgument(0); $this->temporaryStorage = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\TemporaryStorage')->setMethods(['storeDocumentsFromSelect'])->disableOriginalConstructor()->getMock(); }
protected function setUp() { $this->link = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Link', [], [], '', false); $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resource->expects($this->once())->method('getConnection')->will($this->returnValue($this->connection)); $this->import = $this->getMock('Magento\\ImportExport\\Model\\Import', [], [], '', false); $this->importFactory = $this->getMock('Magento\\ImportExport\\Model\\ImportFactory', ['create'], [], '', false); $this->importFactory->expects($this->any())->method('create')->will($this->returnValue($this->import)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->links = $this->objectManagerHelper->getObject('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped\\Links', ['productLink' => $this->link, 'resource' => $this->resource, 'importFactory' => $this->importFactory]); }
/** * @param string $indexName * @param Dimension[] $dimensions * @param string $expected * @dataProvider resolveDataProvider */ public function testResolve($indexName, array $dimensions, $expected) { $dimensions = array_map(function ($demension) { return $this->createDimension($demension[0], $demension[1]); }, $dimensions); $scope = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $scope->expects($this->any())->method('getId')->willReturn(1); $this->resource->expects($this->once())->method('getTableName')->willReturnArgument(0); $this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope); $result = $this->target->resolve($indexName, $dimensions); $this->assertEquals($expected, $result); }
/** * @expectedException \Exception * @expectedExceptionMessage Expected Exception * @throws \Exception */ public function testSaveFailed() { $this->modelMock->expects($this->any())->method('getEventPrefix')->will($this->returnValue('event_prefix')); $this->modelMock->expects($this->any())->method('getEventObject')->will($this->returnValue('event_object')); $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock)); $exception = new \Exception('Expected Exception'); $this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception)); $this->connectionMock->expects($this->once())->method('beginTransaction'); $this->connectionMock->expects($this->once())->method('rollback'); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('event_prefix_save_attribute_before', ['event_object' => $this->attribute, 'object' => $this->modelMock, 'attribute' => ['attribute']]); $this->attribute->saveAttribute($this->modelMock, 'attribute'); }
protected function setUp() { $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $this->selectMock->expects($this->any())->method('from')->will($this->returnValue($this->selectMock)); $this->selectMock->expects($this->any())->method('where')->will($this->returnValue($this->selectMock)); $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->contextMock = $this->getMock('Magento\\Framework\\Model\\ModelResource\\Db\\Context', [], [], '', false); $this->contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->integrationResourceModel = new \Magento\Integration\Model\ResourceModel\Integration($this->contextMock); }
/** * {@inheritDoc} */ protected function setUp() { $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\Context')->disableOriginalConstructor()->getMock(); $this->scopeConfigMock = $this->getMockBuilder('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->getMock(); $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->getMock(); $this->storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock); $this->event = new Event($this->contextMock, $this->scopeConfigMock, $this->storeManagerMock); }
protected function setUp() { $objectManager = new ObjectManager($this); $this->connectionMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['quote', 'quoteIdentifier'])->getMockForAbstractClass(); $this->connectionMock->expects($this->any())->method('quote')->will($this->returnCallback(function ($value) { return sprintf('\'%s\'', $value); })); $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnCallback(function ($value) { return sprintf('`%s`', $value); })); $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resource->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock)); $this->conditionManager = $objectManager->getObject('Magento\\Framework\\Search\\Adapter\\Mysql\\ConditionManager', ['resource' => $this->resource]); }
/** * SetUP method */ protected function setUp() { $helper = new ObjectManager($this); $this->metricsBuilder = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Aggregation\\Builder\\Metrics')->setMethods(['build'])->disableOriginalConstructor()->getMock(); $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock(); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['fetchAssoc', 'select', 'getCaseSql'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->select); $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock(); $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->bucket = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\BucketInterface')->setMethods(['getName', 'getRanges'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->range = $this->getMockBuilder('Magento\\Framework\\Search\\Request\\Aggregation\\Range')->setMethods(['getFrom', 'getTo'])->disableOriginalConstructor()->getMock(); $this->dataProvider = $this->getMockBuilder('Magento\\Framework\\Search\\Adapter\\Mysql\\Aggregation\\DataProviderInterface')->setMethods(['getDataSet', 'execute'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->builder = $helper->getObject('Magento\\Framework\\Search\\Adapter\\Mysql\\Aggregation\\Builder\\Range', ['metricsBuilder' => $this->metricsBuilder, 'resource' => $this->resource]); }