本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::expects方法的具体用法?PHP SearchCriteriaBuilder::expects怎么用?PHP SearchCriteriaBuilder::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetAllOptions
/**
* Run test getAllOptions method
*
* @param bool $isEmpty
* @param array $expected
* @dataProvider dataProviderGetAllOptions
*/
public function testGetAllOptions($isEmpty, array $expected)
{
$filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']);
$taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true);
$this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
$this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with([$filterMock])->willReturnSelf();
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
$this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock);
if (!$isEmpty) {
$taxClassMock->expects($this->once())->method('getClassId')->willReturn(10);
$taxClassMock->expects($this->once())->method('getClassName')->willReturn('class-name');
$items = [$taxClassMock];
$searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
// checking of a lack of re-initialization
for ($i = 10; --$i;) {
$result = $this->customer->getAllOptions();
$this->assertEquals($expected, $result);
}
} else {
$items = [];
$searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
// checking exception
$this->assertEmpty($this->customer->getAllOptions());
}
}
示例2: testGetByIdentifierNamespace
public function testGetByIdentifierNamespace()
{
$userId = 1;
$namespace = 'some_namespace';
$identifier = 'current';
$this->userContext->expects($this->once())->method('getUserId')->willReturn($userId);
$fieldUserId = new Filter([Filter::KEY_FIELD => 'user_id', Filter::KEY_VALUE => $userId, Filter::KEY_CONDITION_TYPE => 'eq']);
$fieldIdentifier = new Filter([Filter::KEY_FIELD => 'identifier', Filter::KEY_VALUE => $identifier, Filter::KEY_CONDITION_TYPE => 'eq']);
$fieldNamespace = new Filter([Filter::KEY_FIELD => 'namespace', Filter::KEY_VALUE => $namespace, Filter::KEY_CONDITION_TYPE => 'eq']);
$bookmarkId = 1;
$bookmark = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkInterface')->getMockForAbstractClass();
$bookmark->expects($this->once())->method('getId')->willReturn($bookmarkId);
$searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass();
$this->filterBuilder->expects($this->at(0))->method('create')->willReturn($fieldUserId);
$this->filterBuilder->expects($this->at(1))->method('create')->willReturn($fieldIdentifier);
$this->filterBuilder->expects($this->at(2))->method('create')->willReturn($fieldNamespace);
$this->searchCriteriaBuilder->expects($this->once())->method('addFilters')->with([$fieldUserId, $fieldIdentifier, $fieldNamespace]);
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$searchResult = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkSearchResultsInterface')->getMockForAbstractClass();
$searchResult->expects($this->once())->method('getTotalCount')->willReturn(1);
$searchResult->expects($this->once())->method('getItems')->willReturn([$bookmark]);
$this->bookmarkRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
$this->bookmarkRepository->expects($this->once())->method('getById')->with($bookmarkId)->willReturn($bookmark);
$this->assertEquals($bookmark, $this->bookmarkManagement->getByIdentifierNamespace($identifier, $namespace));
}
示例3: testResolve
public function testResolve()
{
$documentIds = [1, 2, 3];
$attributeSetIds = [4, 5];
$requestName = 'request_name';
$this->attributeSetFinder->expects($this->once())->method('findAttributeSetIdsByProductIds')->with($documentIds)->willReturn($attributeSetIds);
$searchCriteria = $this->getMock(SearchCriteriaInterface::class);
$this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with('attribute_set_id', $attributeSetIds, 'in')->willReturnSelf();
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$attributeFirst = $this->getMock(ProductAttributeInterface::class);
$attributeFirst->expects($this->once())->method('getAttributeCode')->willReturn('code_1');
$attributeSecond = $this->getMock(ProductAttributeInterface::class);
$attributeSecond->expects($this->once())->method('getAttributeCode')->willReturn('code_2');
$searchResult = $this->getMock(ProductAttributeSearchResultsInterface::class);
$searchResult->expects($this->once())->method('getItems')->willReturn([$attributeFirst, $attributeSecond]);
$this->productAttributeRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
$bucketFirst = $this->getMock(BucketInterface::class);
$bucketFirst->expects($this->once())->method('getField')->willReturn('code_1');
$bucketSecond = $this->getMock(BucketInterface::class);
$bucketSecond->expects($this->once())->method('getField')->willReturn('some_another_code');
$bucketThird = $this->getMock(BucketInterface::class);
$bucketThird->expects($this->once())->method('getName')->willReturn('custom_not_attribute_field');
$this->request->expects($this->once())->method('getAggregation')->willReturn([$bucketFirst, $bucketSecond, $bucketThird]);
$this->request->expects($this->once())->method('getName')->willReturn($requestName);
$this->config->expects($this->once())->method('get')->with($requestName)->willReturn(['aggregations' => ['custom_not_attribute_field' => []]]);
$this->assertEquals([$bucketFirst, $bucketThird], $this->aggregationResolver->resolve($this->request, $documentIds));
}
示例4: setUp
protected function setUp()
{
$this->groupRepositoryInterface = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\GroupRepository', [], [], '', false);
$this->searchCriteriaSearch = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$this->searchCriteriaBuilder = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
$this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($this->searchCriteriaSearch);
$this->storeResolver = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product\\StoreResolver', [], [], '', false);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->tierPrice = $this->objectManagerHelper->getObject('Magento\\CatalogImportExport\\Model\\Import\\Product\\Validator\\TierPrice', ['groupRepository' => $this->groupRepositoryInterface, 'searchCriteriaBuilder' => $this->searchCriteriaBuilder, 'storeResolver' => $this->storeResolver]);
}
示例5: testGetFeeds
public function testGetFeeds()
{
$feeds = ['feed1', 'feed2'];
$searchCriteria = $this->getMockBuilder('\\Magento\\Framework\\Api\\SearchCriteria')->disableOriginalConstructor()->getMock();
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$searchResult = $this->getMockBuilder('\\Magento\\SampleServiceContractNew\\API\\Data\\FeedSearchResultInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$searchResult->expects($this->once())->method('getItems')->willReturn($feeds);
$this->feedRepository->expects($this->once())->method('getList')->willReturn($searchResult);
$this->assertEquals($feeds, $this->block->getFeeds());
}
示例6: testToOptionArray
public function testToOptionArray()
{
$customerGroups = [['label' => __('ALL GROUPS'), 'value' => 32000], ['label' => __('NOT LOGGED IN'), 'value' => 0]];
$this->moduleManagerMock->expects($this->any())->method('isEnabled')->willReturn(true);
$this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
$this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
$this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
$groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
$groupTest->expects($this->any())->method('getCode')->willReturn(__('NOT LOGGED IN'));
$groupTest->expects($this->any())->method('getId')->willReturn(0);
$groups = [$groupTest];
$this->searchResultMock->expects($this->any())->method('getItems')->willReturn($groups);
$this->assertEquals($customerGroups, $this->model->toOptionArray());
}
示例7: setUp
protected function setUp()
{
$this->contextMock = $this->getMockBuilder(ContextInterface::class)->getMockForAbstractClass();
$this->attributeRepositoryMock = $this->getMockBuilder(ProductAttributeRepositoryInterface::class)->getMockForAbstractClass();
$this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)->disableOriginalConstructor()->getMock();
$this->uiElementProcessorMock = $this->getMockBuilder(UiElementProcessor::class)->disableOriginalConstructor()->getMock();
$this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$this->searchResultsMock = $this->getMockBuilder(ProductAttributeSearchResultsInterface::class)->getMockForAbstractClass();
$this->contextMock->expects(static::any())->method('getProcessor')->willReturn($this->uiElementProcessorMock);
$this->searchCriteriaBuilderMock->expects(static::any())->method('addFilter')->willReturnSelf();
$this->searchCriteriaBuilderMock->expects(static::any())->method('create')->willReturn($this->searchCriteriaMock);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->attributesColumn = $this->objectManagerHelper->getObject(AttributesColumn::class, ['context' => $this->contextMock, 'attributeRepository' => $this->attributeRepositoryMock, 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock]);
}
示例8: testGetConfig
public function testGetConfig()
{
$customerId = 1;
$visible = true;
$storeId = 1;
$vaultProviderCode = "vault_provider_code";
$expectedConfig = ['payment' => [VaultPaymentInterface::CODE => [VaultPaymentInterface::CODE . '_item_' . '0' => ['config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component']]]];
$searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass();
$tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
$tokenUiComponentProvider = $this->getMock(TokenUiComponentProviderInterface::class);
$tokenUiComponent = $this->getMock(TokenUiComponentInterface::class);
$this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store);
$this->store->expects(static::once())->method('getId')->willReturn($storeId);
$this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true);
$this->customerSessionMock->expects(self::once())->method('getCustomerId')->willReturn($customerId);
$customerFilterMock = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0);
$visibilityFilterMock = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, $visible, 1);
$this->vaultPayment->expects(static::once())->method('getProviderCode')->willReturn($vaultProviderCode);
$codeFilterMock = $this->createExpectedFilter(PaymentTokenInterface::PAYMENT_METHOD_CODE, $vaultProviderCode, 2);
$this->searchCriteriaBuilderMock->expects(self::once())->method('addFilters')->with([$customerFilterMock, $visibilityFilterMock, $codeFilterMock])->willReturnSelf();
$this->searchCriteriaBuilderMock->expects(self::once())->method('create')->willReturn($searchCriteriaMock);
$this->paymentTokenRepositoryMock->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock);
$searchResultMock->expects(self::once())->method('getItems')->willReturn([$tokenMock]);
$tokenUiComponentProvider->expects(static::once())->method('getComponentForToken')->with($tokenMock)->willReturn($tokenUiComponent);
$tokenUiComponent->expects(static::once())->method('getConfig')->willReturn(['token_code' => 'code']);
$tokenUiComponent->expects(static::once())->method('getName')->willReturn('Vendor_Module/js/vault_component');
$configProvider = new TokensConfigProvider($this->customerSessionMock, $this->paymentTokenRepositoryMock, $this->filterBuilderMock, $this->searchCriteriaBuilderMock, $this->storeManager, $this->vaultPayment, [$vaultProviderCode => $tokenUiComponentProvider]);
static::assertEquals($expectedConfig, $configProvider->getConfig());
}
示例9: testInitAddToCustomerGroups
public function testInitAddToCustomerGroups()
{
$searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false);
$this->groupRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult);
$groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
$expectedCode = 'code';
$expectedId = 'id';
$expectedCustomerGroups = [$expectedCode => $expectedId];
$groupTest->expects($this->once())->method('getCode')->willReturn($expectedCode);
$groupTest->expects($this->once())->method('getId')->willReturn($expectedId);
$groups = [$groupTest];
$groupSearchResult->expects($this->once())->method('getItems')->willReturn($groups);
$this->groupPrice->init();
$this->assertEquals($expectedCustomerGroups, $this->getPropertyValue($this->groupPrice, 'customerGroups'));
}
示例10: getSearchCriteria
/**
* Build search criteria
* @param int $customerId
* @param string $vaultProviderCode
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getSearchCriteria($customerId, $vaultProviderCode)
{
$searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0);
$codeFilter = $this->createExpectedFilter(PaymentTokenInterface::PAYMENT_METHOD_CODE, $vaultProviderCode, 1);
$this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $codeFilter])->willReturnSelf();
$this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria);
return $searchCriteria;
}
示例11: buildSearchCriteria
/**
* Build search criteria
*/
private function buildSearchCriteria()
{
$this->filterBuilder->expects(static::exactly(2))->method('setField')->willReturnSelf();
$this->filterBuilder->expects(static::exactly(2))->method('setValue')->willReturnSelf();
$searchCriteria = new SearchCriteria();
$this->searchCriteriaBuilder->expects(static::once())->method('addFilters')->willReturnSelf();
$this->searchCriteriaBuilder->expects(static::once())->method('create')->willReturn($searchCriteria);
$this->transactionRepository->expects(static::once())->method('getList')->with($searchCriteria)->willReturnSelf();
}
示例12: testGetAllOptionsNameIntegrity
/**
* Run test getAllOptions method for names integrity
*
* @param array $value
* @dataProvider dataProviderGetAllOptionsNameIntegrity
*/
public function testGetAllOptionsNameIntegrity(array $value)
{
$filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']);
$taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true);
$this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_PRODUCT)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
$this->searchCriteriaBuilderMock->expects($this->once())->method('addFilters')->with([$filterMock])->willReturnSelf();
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
$this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock);
$taxClassMock->expects($this->once())->method('getClassId')->willReturn($value['value']);
$taxClassMock->expects($this->once())->method('getClassName')->willReturn($value['label']);
$items = [$taxClassMock];
$searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
$result = $this->product->getAllOptions(false);
$expected = $value;
$this->assertEquals([$expected], $result);
}
示例13: getSearchCriteria
/**
* Build search criteria
* @param int $customerId
* @param string $vaultProviderCode
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getSearchCriteria($customerId, $vaultProviderCode)
{
$searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0);
$codeFilter = $this->createExpectedFilter(PaymentTokenInterface::PAYMENT_METHOD_CODE, $vaultProviderCode, 1);
$isActiveFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_ACTIVE, 1, 2);
// express at expectations
$expiresAtFilter = $this->createExpectedFilter(PaymentTokenInterface::EXPIRES_AT, '2015-01-01 00:00:00', 3);
$this->filterBuilder->expects(static::once())->method('setConditionType')->with('gt')->willReturnSelf();
$this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $codeFilter, $expiresAtFilter, $isActiveFilter])->willReturnSelf();
$this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria);
return $searchCriteria;
}
示例14: testGetProductsWithFilter
public function testGetProductsWithFilter()
{
$products = ['Product1', 'Product2'];
$searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass();
$this->request->expects($this->exactly(2))->method('getParam')->with($this->equalTo('type'))->willReturn('FilterProductType');
$this->filterBuilder->expects($this->once())->method('setField')->with('type_id')->willReturnSelf();
$this->filterBuilder->expects($this->once())->method('setValue')->with($this->equalTo('FilterProductType'))->willReturnSelf();
$filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
$this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
$this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with($this->equalTo([$filter]))->willReturnSelf();
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$this->productRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($products);
$result = $this->block->getProducts();
$this->assertEquals($products, $result);
}
示例15: testCaptureExecute
/**
* @param int $size
* @param string $command
* @covers \Magento\BraintreeTwo\Gateway\Command\CaptureStrategyCommand::execute
* @dataProvider captureDataProvider
*/
public function testCaptureExecute($size, $command)
{
$paymentData = $this->getPaymentDataObjectMock();
$subject['payment'] = $paymentData;
$this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData);
$this->payment->expects(static::once())->method('getAuthorizationTransaction')->willReturn(true);
$this->payment->expects(static::once())->method('getId')->willReturn(1);
$this->filterBuilder->expects(static::exactly(2))->method('setField')->willReturnSelf();
$this->filterBuilder->expects(static::exactly(2))->method('setValue')->willReturnSelf();
$searchCriteria = new SearchCriteria();
$this->searchCriteriaBuilder->expects(static::once())->method('addFilters')->willReturnSelf();
$this->searchCriteriaBuilder->expects(static::once())->method('create')->willReturn($searchCriteria);
$this->transactionRepository->expects(static::once())->method('getList')->with($searchCriteria)->willReturnSelf();
$this->transactionRepository->expects(static::once())->method('getTotalCount')->willReturn($size);
$this->commandPool->expects(static::once())->method('get')->with($command)->willReturn($this->command);
$this->strategyCommand->execute($subject);
}