本文整理匯總了PHP中Magento\Framework\App\ScopeResolverInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP ScopeResolverInterface::expects方法的具體用法?PHP ScopeResolverInterface::expects怎麽用?PHP ScopeResolverInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\App\ScopeResolverInterface
的用法示例。
在下文中一共展示了ScopeResolverInterface::expects方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSearch
public function testSearch()
{
$requestName = 'requestName';
$scope = 333;
$filterField = 'filterField';
$filterValue = 'filterValue';
$filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->disableOriginalConstructor()->getMock();
$filter->expects($this->once())->method('getField')->willReturn($filterField);
$filter->expects($this->once())->method('getValue')->willReturn($filterValue);
$filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->disableOriginalConstructor()->getMock();
$filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
$searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchCriteriaInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$searchCriteria->expects($this->once())->method('getRequestName')->willReturn($requestName);
$searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
$searchResult = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchResult')->disableOriginalConstructor()->getMockForAbstractClass();
$request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$response = $this->getMockBuilder('Magento\\Framework\\Search\\ResponseInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$this->requestBuilder->expects($this->once())->method('setRequestName')->with($requestName);
$this->requestBuilder->expects($this->once())->method('bindDimension')->with('scope', $scope);
$this->requestBuilder->expects($this->any())->method('bind');
$this->requestBuilder->expects($this->once())->method('create')->willReturn($request);
$this->searchEngine->expects($this->once())->method('search')->with($request)->willReturn($response);
$this->searchResponseBuilder->expects($this->once())->method('build')->with($response)->willReturn($searchResult);
$this->scopeResolver->expects($this->once())->method('getScope')->willReturn($scope);
$searchResult = $this->model->search($searchCriteria);
$this->assertInstanceOf('Magento\\Framework\\Api\\Search\\SearchResultInterface', $searchResult);
}
示例2: testSearch
public function testSearch()
{
$requestName = 'requestName';
$scopeId = 333;
$filters = [$this->createFilterMock('array_filter', ['arrayValue1', 'arrayValue2']), $this->createFilterMock('simple_filter', 'filterValue'), $this->createFilterMock('from_filter', ['from' => 30]), $this->createFilterMock('to_filter', ['to' => 100]), $this->createFilterMock('range_filter', ['from' => 60, 'to' => 82])];
$scope = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->disableOriginalConstructor()->getMock();
$filterGroup->expects($this->once())->method('getFilters')->willReturn($filters);
$searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchCriteriaInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$searchCriteria->expects($this->once())->method('getRequestName')->willReturn($requestName);
$searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
$searchResult = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchResult')->disableOriginalConstructor()->getMockForAbstractClass();
$request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$response = $this->getMockBuilder('Magento\\Framework\\Search\\ResponseInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$this->requestBuilder->expects($this->once())->method('setRequestName')->with($requestName);
$this->requestBuilder->expects($this->once())->method('bindDimension')->with('scope', $scopeId);
$this->requestBuilder->expects($this->exactly(6))->method('bind');
$this->requestBuilder->expects($this->once())->method('create')->willReturn($request);
$this->searchEngine->expects($this->once())->method('search')->with($request)->willReturn($response);
$this->searchResponseBuilder->expects($this->once())->method('build')->with($response)->willReturn($searchResult);
$this->scopeResolver->expects($this->once())->method('getScope')->willReturn($scope);
$scope->expects($this->once())->method('getId')->willReturn($scopeId);
$searchResult = $this->model->search($searchCriteria);
$this->assertInstanceOf('Magento\\Framework\\Api\\Search\\SearchResultInterface', $searchResult);
}
示例3: setUp
protected function setUp()
{
$objectManagerHelper = new ObjectManagerHelper($this);
$this->conditionManager = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\ConditionManager')->disableOriginalConstructor()->setMethods(['wrapBrackets'])->getMock();
$this->scopeResolver = $this->getMockBuilder('\\Magento\\Framework\\App\\ScopeResolverInterface')->disableOriginalConstructor()->setMethods(['getScope'])->getMockForAbstractClass();
$this->scope = $this->getMockBuilder('\\Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->setMethods(['getId'])->getMockForAbstractClass();
$this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($this->scope));
$this->config = $this->getMockBuilder('\\Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->setMethods(['getAttribute'])->getMock();
$this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->setMethods(['getBackendTable', 'isStatic', 'getAttributeId', 'getAttributeCode', 'getFrontendInput'])->getMockForAbstractClass();
$this->resource = $resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->setMethods(['getConnection', 'getTableName'])->getMock();
$this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['select', 'getIfNullSql', 'quote'])->getMockForAbstractClass();
$this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'join', 'where', '__toString', 'joinLeft', 'columns', 'having'])->getMock();
$this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
$this->connection->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
$resource->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($this->connection));
$this->filter = $this->getMockBuilder('\\Magento\\Framework\\Search\\Request\\FilterInterface')->disableOriginalConstructor()->setMethods(['getField', 'getValue', 'getType'])->getMockForAbstractClass();
$this->conditionManager->expects($this->any())->method('wrapBrackets')->with($this->select)->will($this->returnCallback(function ($select) {
return '(' . $select . ')';
}));
$this->tableMapper = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper')->disableOriginalConstructor()->getMock();
$this->metadataPoolMock = $this->getMockBuilder(\Magento\Framework\Model\Entity\MetadataPool::class)->disableOriginalConstructor()->getMock();
$metadata = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
$this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata);
$metadata->expects($this->any())->method('getLinkField')->willReturn('entity_id');
$this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Adapter\\Mysql\\Filter\\Preprocessor', ['conditionManager' => $this->conditionManager, 'scopeResolver' => $this->scopeResolver, 'config' => $this->config, 'resource' => $resource, 'attributePrefix' => 'attr_', 'metadataPool' => $this->metadataPoolMock, 'tableMapper' => $this->tableMapper]);
}
示例4: testBuildDimensionWithDefaultScope
public function testBuildDimensionWithDefaultScope()
{
$name = 'scope';
$value = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT;
$scopeId = -123456;
$this->dimension->expects($this->once())->method('getName')->will($this->returnValue($name));
$this->dimension->expects($this->once())->method('getValue')->will($this->returnValue($value));
$this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
$this->scopeResolver->expects($this->once())->method('getScope')->with($value)->will($this->returnValue($this->scope));
$query = $this->builder->build($this->dimension);
$this->assertEquals(sprintf('`%s` = `%s`', \Magento\Framework\Search\Adapter\Mysql\Dimensions::STORE_FIELD_NAME, $scopeId), $query);
}
示例5: testResolve
/**
* @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);
}
示例6: prepareIsAllowed
/**
* @param bool $isEnabled
* @param bool $isActive
* @param bool $isDevAllowed
* @param null|string $scope
*/
protected function prepareIsAllowed($isEnabled, $isActive, $isDevAllowed, $scope = null)
{
$scopeMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false);
$this->stateMock->expects($this->any())->method('isEnabled')->will($this->returnValue($isEnabled));
$this->scopeResolverMock->expects($this->once())->method('getScope')->with($scope)->will($this->returnValue($scopeMock));
$this->configMock->expects($this->once())->method('isActive')->with($scopeMock)->will($this->returnValue($isActive));
$this->configMock->expects($this->exactly((int) $isActive))->method('isDevAllowed')->will($this->returnValue($isDevAllowed));
}
示例7: expectsSetConfig
/**
* Declare calls expectation for setConfig() method
*/
protected function expectsSetConfig($themeId, $localeCode = 'en_US')
{
$this->locale->expects($this->any())->method('getLocaleCode')->will($this->returnValue($localeCode));
$scope = new \Magento\Framework\Object(['code' => 'frontendCode', 'id' => 1]);
$scopeAdmin = new \Magento\Framework\Object(['code' => 'adminCode', 'id' => 0]);
$this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValueMap([[null, $scope], ['admin', $scopeAdmin]]));
$designTheme = new \Magento\Framework\Object(['id' => $themeId]);
$this->viewDesign->expects($this->any())->method('getDesignTheme')->will($this->returnValue($designTheme));
}
示例8: setUp
protected function setUp()
{
$objectManagerHelper = new ObjectManagerHelper($this);
$this->conditionManager = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\ConditionManager')->disableOriginalConstructor()->setMethods(['wrapBrackets'])->getMock();
$this->scopeResolver = $this->getMockBuilder('\\Magento\\Framework\\App\\ScopeResolverInterface')->disableOriginalConstructor()->setMethods(['getScope'])->getMockForAbstractClass();
$this->scope = $this->getMockBuilder('\\Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->setMethods(['getId'])->getMockForAbstractClass();
$this->scopeResolver->expects($this->once())->method('getScope')->will($this->returnValue($this->scope));
$this->config = $this->getMockBuilder('\\Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->setMethods(['getAttribute'])->getMock();
$this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->setMethods(['getBackendTable', 'isStatic', 'getAttributeId'])->getMockForAbstractClass();
$this->resource = $resource = $this->getMockBuilder('\\Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->setMethods(['getConnection', 'getTableName'])->getMock();
$this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['select', 'getIfNullSql'])->getMockForAbstractClass();
$this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', '__toString', 'joinLeft', 'columns', 'having'])->getMock();
$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
$resource->expects($this->atLeastOnce())->method('getConnection')->with(\Magento\Framework\App\Resource::DEFAULT_READ_RESOURCE)->will($this->returnValue($this->connection));
$this->filter = $this->getMockBuilder('\\Magento\\Framework\\Search\\Request\\FilterInterface')->disableOriginalConstructor()->setMethods(['getField', 'getValue'])->getMockForAbstractClass();
$this->conditionManager->expects($this->any())->method('wrapBrackets')->with($this->select)->will($this->returnCallback(function ($select) {
return '(' . $select . ')';
}));
$this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Adapter\\Mysql\\Filter\\Preprocessor', ['conditionManager' => $this->conditionManager, 'scopeResolver' => $this->scopeResolver, 'config' => $this->config, 'resource' => $resource, 'attributePrefix' => 'attr_']);
}
示例9: testGetTreeForAllScope
/**
* Check is possible to get all categories for all store starting from top level root category
*/
public function testGetTreeForAllScope()
{
$rootCategoryId = null;
$depth = null;
$category = null;
$categoriesMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false);
$categoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'categoryMock', false);
$categoriesMock->expects($this->once())->method('getFirstItem')->willReturn($categoryMock);
$categoriesMock->expects($this->once())->method('addFilter')->with('level', ['eq' => 0])->willReturnSelf();
$this->categoriesFactoryMock->expects($this->once())->method('create')->willReturn($categoriesMock);
$nodeMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', [], [], '', false);
$this->categoryTreeMock->expects($this->once())->method('getTree')->with($nodeMock, $depth);
$this->categoryRepositoryMock->expects($this->never())->method('get');
$this->categoryTreeMock->expects($this->once())->method('getRootNode')->with($categoryMock)->willReturn($nodeMock);
$this->scopeResolverMock->expects($this->once())->method('getScope')->willReturn($this->scopeMock);
$this->scopeMock->expects($this->once())->method('getCode')->willReturn(\Magento\Store\Model\Store::ADMIN_CODE);
$this->model->getTree();
}
示例10: testBuildWithoutOutOfStock
public function testBuildWithoutOutOfStock()
{
$scopeId = '113';
$tableSuffix = 'scope113_someNamesomeValue';
$index = 'test_index_name';
$dimensions = [$this->createDimension('scope', $scopeId), $this->createDimension('someName', 'someValue')];
$this->request->expects($this->exactly(2))->method('getDimensions')->willReturn($dimensions);
$this->dimensionScopeResolver->expects($this->once())->method('getScope')->willReturn($this->scopeInterface);
$this->scopeInterface->expects($this->once())->method('getId')->willReturn('someValue');
$this->mockBuild($index, $tableSuffix, false);
$this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn(1);
$this->config->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false));
$this->connection->expects($this->once())->method('quoteInto')->with(' AND stock_index.website_id = ?', 1)->willReturn(' AND stock_index.website_id = 1');
$this->select->expects($this->at(2))->method('where')->with('(someName=someValue)')->willReturnSelf();
$this->select->expects($this->at(3))->method('joinLeft')->with(['stock_index' => 'cataloginventory_stock_status'], 'search_index.entity_id = stock_index.product_id' . ' AND stock_index.website_id = 1', [])->willReturnSelf();
$this->select->expects($this->at(4))->method('where')->with('stock_index.stock_status = ?', 1)->will($this->returnSelf());
$result = $this->target->build($this->request);
$this->assertSame($this->select, $result);
}