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


PHP Db\AbstractDb类代码示例

本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\AbstractDb的典型用法代码示例。如果您正苦于以下问题:PHP AbstractDb类的具体用法?PHP AbstractDb怎么用?PHP AbstractDb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AbstractDb类的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\\ResourceModel\\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);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:AbstractCollectionTest.php

示例2: 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('Magento\\Framework\\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\\ResourceModel\\Db\\AbstractDb', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $objectManager = new ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Quote\\Model\\ResourceModel\\Quote\\Item\\Collection', ['entityFactory' => $this->entityFactoryMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->eventManagerMock, 'resource' => $this->resourceMock]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:CollectionTest.php

示例3: setUp

 protected function setUp()
 {
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'prepareSqlCondition', 'quoteIdentifier'], [], '', false);
     $this->resource = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', [], '', false, true, true, ['getConnection', '__wakeup', 'getMainTable', 'getTable']);
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->resource->expects($this->any())->method('getMainTable')->will($this->returnValue('test_main_table'));
     $this->resource->expects($this->any())->method('getTable')->with('test_main_table')->will($this->returnValue('test_main_table'));
     $this->collection = (new ObjectManager($this))->getObject('Magento\\UrlRewrite\\Model\\ResourceModel\\UrlRewriteCollection', ['storeManager' => $this->storeManager, 'resource' => $this->resource]);
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:14,代码来源:UrlRewriteCollectionTest.php

示例4: setUp

 protected function setUp()
 {
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false);
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb')->setMethods(['getConnection', 'getMainTable', 'getTable'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'query'], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from'], ['adapter' => $this->connectionMock]);
     $this->connectionMock->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('main_table_name');
     $this->resourceMock->expects($this->once())->method('getTable')->will($this->returnArgument(0));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Review\\Model\\ResourceModel\\Review\\Summary\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'resource' => $this->resourceMock]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:CollectionTest.php

示例5: setUp

 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMockBuilder(EntityFactoryInterface::class)->getMockForAbstractClass();
     $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->getMockForAbstractClass();
     $this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)->getMockForAbstractClass();
     $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->getMockForAbstractClass();
     $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass();
     $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->resourceMock = $this->getMockBuilder(AbstractDb::class)->disableOriginalConstructor()->getMock();
     $this->aggregationsMock = $this->getMockBuilder(AggregationInterface::class)->getMockForAbstractClass();
     $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
     $this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
     $this->model = (new ObjectManager($this))->getObject(Collection::class, ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->eventManagerMock, 'storeManager' => $this->storeManagerMock, 'metadataPool' => $this->metadataPoolMock, 'mainTable' => null, 'eventPrefix' => 'test_event_prefix', 'eventObject' => 'test_event_object', 'resourceModel' => null, 'resource' => $this->resourceMock]);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:CollectionTest.php

示例6: testPrepareDataForUpdate

 public function testPrepareDataForUpdate()
 {
     $connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $context = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Framework\\Model\\Context');
     $registryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', 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));
     $resourceCollectionMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->disableOriginalConstructor()->getMockForAbstractClass();
     $abstractModelMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [$context, $registryMock, $resourceMock, $resourceCollectionMock]);
     $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->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'];
     $this->_model->expects($this->once())->method('_prepareDataForTable')->will($this->returnValue($newData));
     $abstractModelMock->addData($newData);
     $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $abstractModelMock->isObjectNew(false);
     $connectionMock->expects($this->once())->method('update')->with('tableName', $newData, 'idFieldName');
     $this->_model->save($abstractModelMock);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:33,代码来源:AbstractDbTest.php

示例7: testGetAllIds

 /**
  * Run test getAllIds method
  *
  * @return void
  */
 public function testGetAllIds()
 {
     $adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['fetchCol'], [], '', false);
     $this->resourceMock->expects($this->once())->method('getIdFieldName')->will($this->returnValue('return-value'));
     $this->selectMock->expects($this->once())->method('getConnection')->will($this->returnValue($adapterMock));
     $adapterMock->expects($this->once())->method('fetchCol')->will($this->returnValue('fetch-result'));
     $this->assertEquals('fetch-result', $this->query->getAllIds());
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:13,代码来源:QueryTest.php

示例8: testUpdateActiveSessionsStatus

 /**
  * @return void
  */
 public function testUpdateActiveSessionsStatus()
 {
     $status = 2;
     $userId = 10;
     $sessionIdToExclude = '20';
     $updateOlderThen = 12345;
     $result = 1;
     $this->resourceMock->expects($this->any())->method('updateStatusByUserId')->with($status, $userId, [\Magento\Security\Model\AdminSessionInfo::LOGGED_IN], [$sessionIdToExclude], $updateOlderThen)->willReturn($result);
     $this->assertEquals($result, $this->collectionMock->updateActiveSessionsStatus($status, $userId, $sessionIdToExclude, $updateOlderThen));
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:13,代码来源:CollectionTest.php

示例9: testSetMainTable

 public function testSetMainTable()
 {
     $setMainTableMethod = new \ReflectionMethod($this->_model, '_setMainTable');
     $setMainTableMethod->setAccessible(true);
     $tableName = $this->_model->getTable('store_website');
     $idFieldName = 'website_id';
     $setMainTableMethod->invoke($this->_model, $tableName);
     $this->assertEquals($tableName, $this->_model->getMainTable());
     $setMainTableMethod->invoke($this->_model, $tableName, $idFieldName);
     $this->assertEquals($tableName, $this->_model->getMainTable());
     $this->assertEquals($idFieldName, $this->_model->getIdFieldName());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:AbstractTest.php

示例10: testGetFields

 public function testGetFields()
 {
     $entityTable = 'entity_table';
     $expectedDescribedTable = ['field1' => null, 'field2' => null];
     $expectedAttributes = ['attribute1' => 'value1', 'attribute2' => 'value2'];
     $expectedResults = array_merge($expectedDescribedTable, $expectedAttributes);
     $this->resource->expects($this->any())->method('getEntityTable')->willReturn($entityTable);
     $this->connection->expects($this->once())->method('describeTable')->with($entityTable)->willReturn($expectedDescribedTable);
     $this->model->expects($this->any())->method('getAttributes')->willReturn($expectedAttributes);
     //check that fields load with null initial value
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
     // Testing loading data from cache.
     $this->connection->expects($this->never())->method('describeTable');
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:MetadataTest.php

示例11: testAddStoreFilter

 /**
  * @param mixed $ignoreData
  * @param 'string' $ignoreSql
  * @dataProvider ignoresDataProvider
  * @return void
  */
 public function testAddStoreFilter($ignoreData, $ignoreSql)
 {
     $typeId = 1;
     $subjectId = 2;
     $subtype = 3;
     $limit = 0;
     $stores = [1, 2];
     $this->resourceMock->expects($this->once())->method('getCurrentStoreIds')->willReturn($stores);
     $this->selectMock->expects($this->at(0))->method('where')->with('event_type_id = ?', $typeId);
     $this->selectMock->expects($this->at(1))->method('where')->with('subject_id = ?', $subjectId);
     $this->selectMock->expects($this->at(2))->method('where')->with('subtype = ?', $subtype);
     $this->selectMock->expects($this->at(3))->method('where')->with('store_id IN(?)', $stores);
     $this->selectMock->expects($this->at(4))->method('where')->with($ignoreSql, $ignoreData);
     $this->collection->addRecentlyFiler($typeId, $subjectId, $subtype, $ignoreData, $limit);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:CollectionTest.php

示例12: __construct

 /**
  * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Store\Model\WebsiteFactory $websiteFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\WebsiteFactory $websiteFactory, \Magento\Eav\Model\Config $eavConfig, $connectionName = null)
 {
     parent::__construct($context, $connectionName);
     $this->_storeManager = $storeManager;
     $this->_websiteFactory = $websiteFactory;
     $this->eavConfig = $eavConfig;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Status.php

示例13: __construct

 /**
  * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
  * @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Category $categoryResource, \Magento\Framework\Model\Entity\MetadataPool $metadataPool, $connectionName = null)
 {
     $this->_storeManager = $storeManager;
     $this->_categoryResource = $categoryResource;
     parent::__construct($context, $connectionName);
     $this->metadataPool = $metadataPool;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:14,代码来源:Category.php

示例14: _beforeSave

 /**
  * Prepare rule's active "from" and "to" dates
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $this->resolveDate($object, 'from_date');
     $this->resolveDate($object, 'to_date');
     parent::_beforeSave($object);
     return $this;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:13,代码来源:AbstractResource.php

示例15: load

 public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
 {
     if (is_numeric($value) && is_null($field)) {
         $field = 'customer_id';
     }
     return parent::load($object, $value, $field);
 }
开发者ID:uchenic,项目名称:magento2-module-survey,代码行数:7,代码来源:UserMap.php


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