本文整理汇总了PHP中Magento\Framework\DB\Select::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Select::expects方法的具体用法?PHP Select::expects怎么用?PHP Select::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DB\Select
的用法示例。
在下文中一共展示了Select::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
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]);
}
示例2: testRender
public function testRender()
{
$sql = 'SELECT';
$expectedResult = $sql . ' ' . Select::SQL_DISTINCT . ' ';
$this->selectMock->expects($this->once())->method('getPart')->with(Select::DISTINCT)->willReturn(true);
$this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
}
示例3: testRender
/**
* @param array $columns
* @param string $sql
* @param string $expectedResult
* @dataProvider renderDataProvider
*/
public function testRender($columns, $sql, $expectedResult)
{
$mapValues = [['column', null, '`column`'], [['table', 'column'], null, '`table`.`column`'], [['table', 'column'], 'alias', '`table`.`column` AS `alias`']];
$this->quoteMock->expects($this->any())->method('quoteColumnAs')->willReturnMap($mapValues);
$this->selectMock->expects($this->exactly(2))->method('getPart')->with(Select::COLUMNS)->willReturn($columns);
$this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
}
示例4: testAddUnsecureUrlsFilter
public function testAddUnsecureUrlsFilter()
{
$this->collection->expects($this->at(0))->method('_translateCondition')->with('endpoint', ['like' => 'http:%'])->will($this->returnValue('endpoint like \'http:%\''));
$this->collection->expects($this->at(1))->method('_translateCondition')->with('identity_link_url', ['like' => 'http:%'])->will($this->returnValue('identity_link_url like \'http:%\''));
$this->select->expects($this->once())->method('where')->with($this->equalTo('(endpoint like \'http:%\') OR (identity_link_url like \'http:%\')'), $this->equalTo(null), $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION));
$this->collection->addUnsecureUrlsFilter();
}
示例5: setUp
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]);
}
示例6: testRender
public function testRender()
{
$sql = 'SELECT';
$expectedResult = $sql . ' ' . Select::SQL_HAVING . ' having1 having2';
$mapValues = [[Select::FROM, true], [Select::HAVING, ['having1', 'having2']]];
$this->selectMock->expects($this->any())->method('getPart')->willReturnMap($mapValues);
$this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
}
示例7: testRender
/**
* @param array $from
* @param string $sql
* @param string $expectedResult
* @dataProvider renderDataProvider
*/
public function testRender($from, $sql, $expectedResult)
{
$this->quoteMock->expects($this->any())->method('quoteIdentifier')->willReturnArgument(0);
$this->quoteMock->expects($this->any())->method('quoteTableAs')->willReturnCallback(function ($tableName, $correlationName) {
return $tableName . ' AS ' . $correlationName;
});
$this->selectMock->expects($this->once())->method('getPart')->with(Select::FROM)->willReturn($from);
$this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
}
示例8: setUp
protected function setUp()
{
$this->entityModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], [], '', false);
$attrSetColFactory = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
$attrSetCollection = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', [], [], '', false);
$attrColFactory = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
$attributeSet = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], [], '', false);
$attrCollection = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\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);
$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('getApplyTo')->willReturn(['simple']);
$attribute->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
$attribute->expects($this->any())->method('usesSource')->willReturn(true);
$entityAttributes = [['attribute_id' => 'attribute_id', 'attribute_set_name' => 'attributeSetName'], ['attribute_id' => 'boolean_attribute', 'attribute_set_name' => 'attributeSetName']];
$attribute1 = clone $attribute;
$attribute2 = clone $attribute;
$attribute1->expects($this->any())->method('getId')->willReturn('1');
$attribute1->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
$attribute1->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
$attribute1->expects($this->any())->method('isStatic')->willReturn(true);
$attribute2->expects($this->any())->method('getId')->willReturn('2');
$attribute2->expects($this->any())->method('getAttributeCode')->willReturn('boolean_attribute');
$attribute2->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
$attribute2->expects($this->any())->method('isStatic')->willReturn(false);
$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturnOnConsecutiveCalls(['option1', 'option2'], ['yes' => 1, 'no' => 0]);
$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([$attribute1, $attribute2]);
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
$attrCollection->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', ['in' => ['attribute_id', 'boolean_attribute']])->willReturn([$attribute1, $attribute2]);
$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));
$connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$connection->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
$this->select->expects($this->any())->method('getConnection')->willReturn($connection);
$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->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();
}
示例9: testRender
public function testRender()
{
$sql = 'SELECT';
$expectedResult = $sql . ' ' . Select::SQL_GROUP_BY . ' group1' . ",\n\t" . 'group2';
$mapValues = [[Select::FROM, true], [Select::GROUP, ['group1', 'group2']]];
$this->selectMock->expects($this->exactly(3))->method('getPart')->willReturnMap($mapValues);
$this->quoteMock->expects($this->exactly(2))->method('quoteIdentifier')->willReturnArgument(0);
$this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
}
示例10: 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));
}
示例11: testMapFields
/**
* Run test mapFields method
*
* @return void
*/
public function testMapFields()
{
$fields = [['test-correlation-name', 'test-field', 'test-alias'], ['test-correlation-name', 'test-field', null], ['test-correlation-name', 'test-field', 'test-alias-unique']];
/** @var \Magento\Framework\DB\GenericMapper|\PHPUnit_Framework_MockObject_MockObject $geneticMapper */
$geneticMapper = $this->getMock('Magento\\Framework\\DB\\GenericMapper', ['getSelect'], [], '', false);
$geneticMapper->expects($this->any())->method('getSelect')->will($this->returnValue($this->selectMock));
$this->selectMock->expects($this->once())->method('getPart')->with(\Magento\Framework\DB\Select::COLUMNS)->willReturn([]);
$this->selectMock->expects($this->once())->method('setPart')->with(\Magento\Framework\DB\Select::COLUMNS, $this->equalTo($fields));
$geneticMapper->mapFields($fields);
}
示例12: mockBuild
protected function mockBuild($index, $tableSuffix)
{
$this->request->expects($this->once())->method('getIndex')->will($this->returnValue($index));
$this->resource->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($index) {
return is_array($index) ? $index[0] . $index[1] : $index;
}));
$this->select->expects($this->once())->method('from')->with(['search_index' => $index . $tableSuffix], ['entity_id' => 'product_id'])->will($this->returnSelf());
$this->select->expects($this->at(1))->method('joinLeft')->with(['category_index' => 'catalog_category_product_index'], 'search_index.product_id = category_index.product_id' . ' AND search_index.store_id = category_index.store_id', [])->will($this->returnSelf());
$this->select->expects($this->at(2))->method('joinLeft')->with(['cea' => 'catalog_eav_attribute'], 'search_index.attribute_id = cea.attribute_id', ['search_weight'])->will($this->returnSelf());
$this->select->expects($this->at(3))->method('joinLeft')->with(['cpie' => $this->resource->getTableName('catalog_product_index_eav')], 'search_index.product_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id', [])->willReturnSelf();
}
示例13: testAddOrdersFilter
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));
}
示例14: testExecute
public function testExecute()
{
$identifier = '100000001';
$context = ['store_id' => 1];
$expectedData = ['entity_id' => 1];
$this->select->expects($this->once())->method('from')->with(['t' => 'entity_table'])->willReturnSelf();
$this->select->expects($this->at(1))->method('where')->with('identifier = ?', $identifier)->willReturnSelf();
$this->select->expects($this->at(2))->method('where')->with('store_id = ?', 1)->willReturnSelf();
$this->connection->expects($this->once())->method('fetchRow')->willReturn($expectedData);
$actualData = $this->subject->execute('Test\\Entity\\Type', $identifier, $context);
$this->assertEquals($expectedData, $actualData);
}
示例15: testApply
public function testApply()
{
$filter = new Filter();
$filter->setValue('test');
$this->collectionAbstractDbMock->expects($this->any())->method('getMainTable')->willReturn('testTable');
$this->collectionAbstractDbMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
$this->connectionMock->expects($this->once())->method('getIndexList')->willReturn([['INDEX_TYPE' => 'FULLTEXT', 'COLUMNS_LIST' => ['col1', 'col2']]]);
$this->selectMock->expects($this->once())->method('getPart')->willReturn([]);
$this->selectMock->expects($this->once())->method('where')->willReturn(null);
$this->collectionAbstractDbMock->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
$this->fulltextFilter->apply($this->collectionAbstractDbMock, $filter);
}