本文整理汇总了PHP中Magento\Framework\Api\FilterBuilder::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterBuilder::expects方法的具体用法?PHP FilterBuilder::expects怎么用?PHP FilterBuilder::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\FilterBuilder
的用法示例。
在下文中一共展示了FilterBuilder::expects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: testPrepare
/**
* Run test prepare method
*
* @param array $data
* @param array $filterData
* @param array|null $expectedCondition
* @dataProvider getPrepareDataProvider
* @return void
*/
public function testPrepare($data, $filterData, $expectedCondition)
{
$name = $data['name'];
/** @var UiComponentInterface $uiComponent */
$uiComponent = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false);
$uiComponent->expects($this->any())->method('getContext')->willReturn($this->contextMock);
$this->contextMock->expects($this->any())->method('getNamespace')->willReturn(Select::NAME);
$this->contextMock->expects($this->any())->method('addComponentDefinition')->with(Select::NAME, ['extends' => Select::NAME]);
$this->contextMock->expects($this->any())->method('getFiltersParams')->willReturn($filterData);
/** @var DataProviderInterface $dataProvider */
$dataProvider = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface', ['addFilter'], '', false);
$this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProvider);
if ($expectedCondition !== null) {
$filterMock = $this->getMock('Magento\\Framework\\Api\\Filter');
$this->filterBuilderMock->expects($this->any())->method('setConditionType')->with($expectedCondition)->willReturnSelf();
$this->filterBuilderMock->expects($this->any())->method('setField')->with($name)->willReturnSelf();
$this->filterBuilderMock->expects($this->any())->method('setValue')->willReturnSelf();
$this->filterBuilderMock->expects($this->any())->method('create')->willReturn($filterMock);
$dataProvider->expects($this->any())->method('addFilter')->with($filterMock);
}
/** @var \Magento\Framework\Data\OptionSourceInterface $selectOptions */
$selectOptions = $this->getMockForAbstractClass('Magento\\Framework\\Data\\OptionSourceInterface', [], '', false);
$this->uiComponentFactory->expects($this->any())->method('create')->with($name, Select::COMPONENT, ['context' => $this->contextMock, 'options' => $selectOptions])->willReturn($uiComponent);
$date = new Select($this->contextMock, $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, $selectOptions, [], $data);
$date->prepare();
}
示例3: testLike
/**
* Test a search using 'like' condition
*/
public function testLike()
{
$attributeCode = 'description';
$attributeCodeId = 42;
$attribute = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
$attribute->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
$this->eavConfig->expects($this->once())->method('getAttribute')->with(Product::ENTITY, $attributeCodeId)->willReturn($attribute);
$filtersData = ['catalog_product_entity_text' => [$attributeCodeId => ['like' => 'search text']]];
$this->filterBuilder->expects($this->once())->method('setField')->with($attributeCode)->willReturn($this->filterBuilder);
$this->filterBuilder->expects($this->once())->method('setValue')->with('search text')->willReturn($this->filterBuilder);
$filter = $this->getMock('Magento\\Framework\\Api\\Filter');
$this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
$criteria = $this->getMock('Magento\\Framework\\Api\\Search\\SearchCriteria', [], [], '', false);
$this->criteriaBuilder->expects($this->once())->method('create')->willReturn($criteria);
$criteria->expects($this->once())->method('setRequestName')->with('advanced_search_container');
$tempTable = $this->getMock('Magento\\Framework\\DB\\Ddl\\Table', [], [], '', false);
$temporaryStorage = $this->getMock('Magento\\Framework\\Search\\Adapter\\Mysql\\TemporaryStorage', [], [], '', false);
$temporaryStorage->expects($this->once())->method('storeApiDocuments')->willReturn($tempTable);
$this->temporaryStorageFactory->expects($this->once())->method('create')->willReturn($temporaryStorage);
$searchResult = $this->getMock('Magento\\Framework\\Api\\Search\\SearchResultInterface', [], [], '', false);
$this->search->expects($this->once())->method('search')->willReturn($searchResult);
// addFieldsToFilter will load filters,
// then loadWithFilter will trigger _renderFiltersBefore code in Advanced/Collection
$this->assertSame($this->advancedCollection, $this->advancedCollection->addFieldsToFilter($filtersData)->loadWithFilter());
}
示例4: 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());
}
}
示例5: testApplyFilterModifierWith
/**
* @param $filterModifier
* @param $filterName
* @param $conditionType
* @param $value
* @return void
* @dataProvider getApplyFilterModifierDataProvider
*/
public function testApplyFilterModifierWith($filterModifier, $filterName, $conditionType, $value)
{
$filter = $this->getMock('Magento\\Framework\\Api\\Filter');
$this->request->expects($this->once())->method('getParam')->with(\Magento\Ui\Component\Filters\FilterModifier::FILTER_MODIFIER)->willReturn($filterModifier);
$this->filterBuilder->expects($this->once())->method('setConditionType')->with($conditionType)->willReturnSelf();
$this->filterBuilder->expects($this->once())->method('setField')->with($filterName)->willReturnSelf();
$this->filterBuilder->expects($this->once())->method('setValue')->with($value)->willReturnSelf();
$this->filterBuilder->expects($this->once())->method('create')->with()->willReturn($filter);
$this->dataProvider->expects($this->once())->method('addFilter')->with($filter);
$this->unit->applyFilterModifier($this->dataProvider, $filterName);
}
示例6: createExpectedFilter
/**
* @param string $field
* @param mixed $value
* @param int $atIndex
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createExpectedFilter($field, $value, $atIndex)
{
$filterObject = $this->getMockBuilder(Filter::class)->disableOriginalConstructor()->getMock();
$this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex))->method('setField')->with($field)->willReturnSelf();
$this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex))->method('setValue')->with($value)->willReturnSelf();
$this->filterBuilderMock->expects(new MethodInvokedAtIndex($atIndex))->method('create')->willReturn($filterObject);
return $filterObject;
}
示例7: 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();
}
示例8: 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);
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
示例12: testGetDataSourceDataWithoutId
public function testGetDataSourceDataWithoutId()
{
$requestFieldName = 'request_id';
$dataSource = [];
/** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */
$dataProviderMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface')->getMock();
$dataProviderMock->expects($this->once())->method('getRequestFieldName')->willReturn($requestFieldName);
$dataProviderMock->expects($this->never())->method('getPrimaryFieldName');
$this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProviderMock);
$this->contextMock->expects($this->once())->method('getRequestParam')->with($requestFieldName)->willReturn(null);
$this->filterBuilderMock->expects($this->never())->method('setField');
$this->filterBuilderMock->expects($this->never())->method('setValue');
$this->filterBuilderMock->expects($this->never())->method('create');
$dataProviderMock->expects($this->never())->method('addFilter');
$dataProviderMock->expects($this->never())->method('getData');
$this->assertEquals($dataSource, $this->model->getDataSourceData());
}
示例13: testGetListByCustomerId
/**
* Run test for getListByCustomerId method
*/
public function testGetListByCustomerId()
{
/** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
$tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
/** @var Filter| $filterMock */
$filterMock = $this->getMockBuilder(Filter::class)->disableOriginalConstructor()->getMock();
$searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$searchResult = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass();
$this->filterBuilderMock->expects(self::once())->method('setField')->with(PaymentTokenInterface::CUSTOMER_ID)->willReturnSelf();
$this->filterBuilderMock->expects(self::once())->method('setValue')->with(1)->willReturnSelf();
$this->filterBuilderMock->expects(self::once())->method('create')->willReturn($filterMock);
$this->searchCriteriaBuilderMock->expects(self::once())->method('addFilters')->with([$filterMock])->willReturnSelf();
$this->searchCriteriaBuilderMock->expects(self::once())->method('create')->willReturn($searchCriteria);
$this->paymentTokenRepositoryMock->expects(self::once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
$searchResult->expects(self::once())->method('getItems')->willReturn([$tokenMock]);
self::assertEquals([$tokenMock], $this->paymentTokenManagement->getListByCustomerId(1));
}
示例14: testGetDataSourceDataWithoutId
public function testGetDataSourceDataWithoutId()
{
$requestFieldName = 'request_id';
$primaryFieldName = 'primary_id';
$fieldId = null;
$row = ['key' => 'value'];
$data = [$fieldId => $row];
$dataSource = ['data' => $row];
/** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */
$dataProviderMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProviderInterface')->getMock();
$dataProviderMock->expects($this->once())->method('getRequestFieldName')->willReturn($requestFieldName);
$dataProviderMock->expects($this->once())->method('getPrimaryFieldName')->willReturn($primaryFieldName);
$this->contextMock->expects($this->any())->method('getDataProvider')->willReturn($dataProviderMock);
$this->contextMock->expects($this->once())->method('getRequestParam')->with($requestFieldName)->willReturn($fieldId);
/** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */
$filterMock = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->disableOriginalConstructor()->getMock();
$this->filterBuilderMock->expects($this->once())->method('setField')->with($primaryFieldName)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('setValue')->with($fieldId)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
$dataProviderMock->expects($this->once())->method('addFilter')->with($filterMock);
$dataProviderMock->expects($this->once())->method('getData')->willReturn($data);
$this->assertEquals($dataSource, $this->model->getDataSourceData());
}