本文整理汇总了PHP中Magento\Framework\DB\Adapter\Pdo\Mysql::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Mysql::expects方法的具体用法?PHP Mysql::expects怎么用?PHP Mysql::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DB\Adapter\Pdo\Mysql
的用法示例。
在下文中一共展示了Mysql::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPurge
/**
* Test purge method
*/
public function testPurge()
{
$this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->adapterMock));
$this->appResourceMock->expects($this->once())->method('getTableName')->will($this->returnValue('sales_flat_invoice_grid'));
$this->adapterMock->expects($this->once())->method('delete')->with('sales_flat_invoice_grid', ['fi.field = ?' => 1])->will($this->returnValue(1));
$this->assertEquals(1, $this->grid->purge(1, 'fi.field'));
}
示例2: testAddStoreFilterIfStoreIsInt
/**
* @param int $storeId
* @param bool $withAdmin
* @param array $condition
* @dataProvider dataProviderForTestAddStoreFilterIfStoreIsInt
* @covers \Magento\UrlRewrite\Model\Resource\UrlRewriteCollection
*/
public function testAddStoreFilterIfStoreIsInt($storeId, $withAdmin, $condition)
{
$store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
$store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
$this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
$this->adapter->expects($this->once())->method('prepareSqlCondition')->with('store_id', ['in' => $condition]);
$this->collection->addStoreFilter($storeId, $withAdmin);
}
示例3: testSelectByCompositeKey
public function testSelectByCompositeKey()
{
$selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$selectMock->expects($this->once())->method('from')->will($this->returnValue($selectMock));
$selectMock->expects($this->exactly(2))->method('where')->will($this->returnValue($selectMock));
$this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
$this->adapterMock->expects($this->once())->method('fetchRow');
$this->nonceResource->selectByCompositeKey('nonce', 5);
}
示例4: testSelectTokenByCustomerId
public function testSelectTokenByCustomerId()
{
$selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$selectMock->expects($this->once())->method('from')->will($this->returnValue($selectMock));
$selectMock->expects($this->exactly(2))->method('where')->will($this->returnValue($selectMock));
$this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
$this->adapterMock->expects($this->once())->method('fetchRow');
$this->tokenResource->selectTokenByCustomerId(5);
}
示例5: processAttributeGetter
protected function processAttributeGetter($dbAttributes)
{
$select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$this->connection->expects($this->once())->method('select')->will($this->returnValue($select));
$select->expects($this->once())->method('from')->will($this->returnSelf());
$select->expects($this->once())->method('where')->will($this->returnSelf());
$this->connection->expects($this->once())->method('fetchAll')->with($select)->will($this->returnValue($dbAttributes));
$this->link->expects($this->any())->method('getAttributeTypeTable')->will($this->returnValue('table_name'));
}
示例6: testAddFieldToFilter
/**
* @test
*/
public function testAddFieldToFilter()
{
$field = 'name';
$value = 'test_filter';
$searchSql = 'sql query';
$this->connection->expects($this->any())->method('quoteIdentifier')->willReturn($searchSql);
$this->connection->expects($this->any())->method('prepareSqlCondition')->willReturn($searchSql);
$this->select->expects($this->once())->method('where')->with($searchSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION);
$this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value));
}
示例7: testAssignState
public function testAssignState()
{
$state = 'processing';
$status = 'processing';
$isDefault = 1;
$visibleOnFront = 1;
$tableName = 'sales_order_status_state';
$this->connectionMock->expects($this->once())->method('update')->with($this->equalTo($tableName), $this->equalTo(['is_default' => 0]), $this->equalTo(['state = ?' => $state]));
$this->connectionMock->expects($this->once())->method('insertOnDuplicate')->with($this->equalTo($tableName), $this->equalTo(['status' => $status, 'state' => $state, 'is_default' => $isDefault, 'visible_on_front' => $visibleOnFront]));
$this->model->assignState($status, $state, $isDefault, $visibleOnFront);
}
示例8: setUp
protected function setUp()
{
$this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
$this->connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql')->disableOriginalConstructor()->getMock();
$this->connection->expects($this->any())->method('select')->willReturn($this->select);
$this->resource = $this->getMockBuilder('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb')->disableOriginalConstructor()->setMethods(['getConnection', 'getMainTable', 'getTable'])->getMockForAbstractClass();
$this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
$this->resource->expects($this->any())->method('getMainTable')->willReturn('table_test');
$this->resource->expects($this->any())->method('getTable')->willReturn('test');
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
}
示例9: testGetTimeInSecondsSinceCreation
public function testGetTimeInSecondsSinceCreation()
{
$selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$selectMock->expects($this->any())->method('from')->will($this->returnValue($selectMock));
$selectMock->expects($this->any())->method('reset')->will($this->returnValue($selectMock));
$selectMock->expects($this->any())->method('columns')->will($this->returnValue($selectMock));
$selectMock->expects($this->any())->method('where')->will($this->returnValue($selectMock));
$this->adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
$this->adapterMock->expects($this->once())->method('fetchOne');
$this->consumerResource->getTimeInSecondsSinceCreation(1);
}
示例10: testGetTaxItemsByOrderId
public function testGetTaxItemsByOrderId()
{
$orderId = 1;
$taxItems = [['tax_id' => 1, 'tax_percent' => 5, 'item_id' => 1, 'taxable_item_type' => 4, 'associated_item_id' => 1, 'real_amount' => 12, 'real_base_amount' => 12]];
$select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
$this->adapterMock->expects($this->once())->method('select')->willReturn($select);
$select->expects($this->once())->method('from')->with(['item' => 'sales_order_tax_item'], ['tax_id', 'tax_percent', 'item_id', 'taxable_item_type', 'associated_item_id', 'real_amount', 'real_base_amount'])->willReturnSelf();
$select->expects($this->once())->method('join')->with(['tax' => 'sales_order_tax'], 'item.tax_id = tax.tax_id', ['code', 'title', 'order_id'])->willReturnSelf();
$select->expects($this->once())->method('where')->with('tax.order_id = ?', $orderId)->willReturnSelf();
$this->adapterMock->expects($this->once())->method('fetchAll')->with($select)->willReturn($taxItems);
$this->assertEquals($taxItems, $this->taxItem->getTaxItemsByOrderId($orderId));
}
示例11: testSaveFailed
/**
* @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->adapterMock));
$exception = new \Exception('Expected Exception');
$this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception));
$this->adapterMock->expects($this->once())->method('beginTransaction');
$this->adapterMock->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');
}
示例12: setUp
public function setUp()
{
$this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
$this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History\\Validator', [], [], '', false);
$this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
$this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
$this->adapterMock->expects($this->any())->method('insert');
$this->adapterMock->expects($this->any())->method('lastInsertId');
$this->historyResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Status\\History', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock]);
}
示例13: testGetUnnotifiedForInstance
public function testGetUnnotifiedForInstance()
{
$orderId = 100000512;
$entityType = 'order';
$order = $this->getMock('Magento\\Sales\\Model\\Order', ['__wakeup', 'getEntityType', 'getId'], [], '', false);
$order->expects($this->once())->method('getEntityType')->will($this->returnValue($entityType));
$order->expects($this->once())->method('getId')->will($this->returnValue($orderId));
$this->connectionMock = $this->collection->getResource()->getReadConnection();
$this->connectionMock->expects($this->exactly(3))->method('prepareSqlCondition')->will($this->returnValueMap([['entity_name', $entityType, 'sql-string'], ['is_customer_notified', 0, 'sql-string'], ['parent_id', $orderId, 'sql-string']]));
$result = $this->collection->getUnnotifiedForInstance($order);
$this->assertEquals($this->historyItemMock, $result);
}
示例14: setUp
/**
* Mock class dependencies
*/
protected function setUp()
{
$this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
$this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
$this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
$this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
$this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
$this->resourceMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], [], '', false);
$this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
$objectManager = new ObjectManager($this);
$this->collection = $objectManager->getObject('Magento\\Quote\\Model\\Resource\\Quote\\Item\\Collection', ['entityFactory' => $this->entityFactoryMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->eventManagerMock, 'resource' => $this->resourceMock]);
}
示例15: setUp
protected function setUp()
{
$this->entityModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], [], '', false);
$attrSetColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
$attrSetCollection = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', [], [], '', false);
$attrColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
$attributeSet = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], [], '', false);
$attrCollection = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Collection', ['addFieldToFilter'], [], '', false);
$attribute = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getId', 'getIsVisible', 'getIsGlobal', 'getIsRequired', 'getIsUnique', 'getFrontendLabel', 'isStatic', 'getApplyTo', 'getDefaultValue', 'usesSource', 'getFrontendInput'], [], '', false);
$entityAttributes = ['attribute_id' => 'attributeSetName'];
$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturn(['option1', 'option2']);
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute]);
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
$attribute->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
$attribute->expects($this->any())->method('getId')->willReturn('1');
$attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
$attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
$attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
$attribute->expects($this->any())->method('getIsUnique')->willReturn(true);
$attribute->expects($this->any())->method('getFrontendLabel')->willReturn('frontend_label');
$attribute->expects($this->any())->method('isStatic')->willReturn(true);
$attribute->expects($this->any())->method('getApplyTo')->willReturn(['simple']);
$attribute->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
$attribute->expects($this->any())->method('usesSource')->willReturn(true);
$attribute->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
$attrCollection->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', ['in' => [key($entityAttributes)]])->willReturn([$attribute]);
$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', 'getAdapter'], [], '', 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));
$adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
$this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
$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('fetchPairs')->will($this->returnValue($entityAttributes));
$this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['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->objectManagerHelper = new ObjectManagerHelper($this);
$this->simpleType = $this->objectManagerHelper->getObject('Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\Simple', ['attrSetColFac' => $attrSetColFactory, 'prodAttrColFac' => $attrColFactory, 'params' => [$this->entityModel, 'simple'], 'resource' => $this->resource]);
$this->abstractType = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMockForAbstractClass();
}