本文整理汇总了PHP中Magento\Framework\DB\Adapter\Pdo\Mysql类的典型用法代码示例。如果您正苦于以下问题:PHP Mysql类的具体用法?PHP Mysql怎么用?PHP Mysql使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mysql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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]);
}
示例3: 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]);
}
示例4: 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();
}
示例5: testUnshiftOrder
/**
* @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql $adapter
* @depends testSetAddOrder
*/
public function testUnshiftOrder($adapter)
{
$renderer = $this->getSelectRenderer($this->objectManager);
$select = new \Magento\Framework\DB\Select($adapter, $renderer);
$adapter->expects($this->any())->method('select')->willReturn($select);
$this->collection->setConnection($adapter);
$this->collection->addOrder('some_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
$this->collection->unshiftOrder('other_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
$this->collection->load();
$selectOrders = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::ORDER);
$this->assertEquals('other_field ASC', (string) array_shift($selectOrders));
$this->assertEquals('some_field ASC', (string) array_shift($selectOrders));
$this->assertEmpty(array_shift($selectOrders));
}
示例6: setUp
public function setUp()
{
$this->addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['__wakeup', 'getOrderId', 'hasDataChanges'], [], '', false);
$this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
$this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['describeTable', 'insert', 'lastInsertId'], [], '', false);
$this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address\\Validator', [], [], '', false);
$this->gridPoolMock = $this->getMock('Magento\\Sales\\Model\\Resource\\GridPool', ['refreshByOrderId'], [], '', 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->addressResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Address', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock, 'gridPool' => $this->gridPoolMock]);
}
示例7: setUp
/**
* Init
*/
public function setUp()
{
$this->addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['__wakeup', 'getOrderId', 'hasDataChanges', 'beforeSave', 'afterSave', 'validateBeforeSave', 'getOrder'], [], '', false);
$this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['__wakeup', 'getId'], [], '', false);
$this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
$this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$this->entitySnapshotMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\VersionControl\\Snapshot', [], [], '', false);
$this->relationCompositeMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\VersionControl\\RelationComposite', [], [], '', false);
$this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
$objectManager = new \Magento\Framework\TestFramework\Unit\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->addressResource = $objectManager->getObject('Magento\\Quote\\Model\\Resource\\Quote\\Address', ['resource' => $this->appResourceMock, 'entitySnapshot' => $this->entitySnapshotMock, 'entityRelationComposite' => $this->relationCompositeMock]);
}
示例8: 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'));
}
示例9: doInsert
public function doInsert()
{
$tbl = $this->_resource->getTableName(Account::ENTITY_NAME);
$bind = [Account::ATTR_CUST_ID => 1, Account::ATTR_ASSET_TYPE_ID => 2, Account::ATTR_BALANCE => 123.45];
$this->_conn->insert($tbl, $bind);
$result = $this->_conn->lastInsertId($tbl);
return $result;
}
示例10: 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);
}
示例11: 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);
}
示例12: 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'));
}
示例13: 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);
}
示例14: 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));
}
示例15: 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);
}