/** * 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()); } }
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)); }
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)); }
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]); }
public function testGetCommentsList() { $this->filterBuilderMock->expects($this->once())->method('setField')->with('parent_id')->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('setValue')->with(123)->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($this->filterMock); $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with(['eq' => $this->filterMock])->willReturn($this->filterBuilderMock); $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($this->searchCriteriaMock); $this->orderStatusHistoryRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->orderSearchResultMock); $this->assertEquals($this->orderSearchResultMock, $this->orderService->getCommentsList(123)); }
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()); }
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()); }
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]); }
/** * Run test getCommentsList method */ public function testGetCommentsList() { $id = 25; $returnValue = 'return-value'; $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false); $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $this->filterBuilderMock->expects($this->once())->method('setField')->with('parent_id')->will($this->returnSelf()); $this->filterBuilderMock->expects($this->once())->method('setValue')->with($id)->will($this->returnSelf()); $this->filterBuilderMock->expects($this->once())->method('create')->will($this->returnValue($filterMock)); $this->criteriaBuilderMock->expects($this->once())->method('addFilter')->with(['eq' => $filterMock]); $this->criteriaBuilderMock->expects($this->once())->method('create')->will($this->returnValue($searchCriteriaMock)); $this->commentRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->will($this->returnValue($returnValue)); $this->assertEquals($returnValue, $this->shipmentService->getCommentsList($id)); }
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()); }
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')); }
/** * 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; }
/** * 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(); }
/** * @param int $id * @param array $collectionIds * @param $conditionType * @dataProvider getDataProvider */ public function testGet($id, array $collectionIds, $conditionType) { $filter = $this->getMock('Magento\\Framework\\Api\\Filter', ['getConditionType', 'getField', 'getValue'], [], '', false); $filter->expects($this->any())->method('getConditionType')->willReturn($conditionType); $this->filterBuilder->expects($this->once())->method('setField')->with('transaction_id')->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('setValue')->with($id)->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('setConditionType')->with('eq')->willReturnSelf(); $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter); $filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $filterGroup->expects($this->any())->method('getFilters')->willReturn($filter); $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $searchCriteria->expects($this->any())->method('getFilterGroups')->willReturn([$filterGroup]); $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with([$filter]); $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria); $transactionModelMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock(); $transactionModelMock->expects($this->any())->method('getId')->will($this->returnValue($id)); $this->prepareCollection($transactionModelMock, $collectionIds); $this->assertSame($transactionModelMock, $this->transactionRepository->get($id)); }
/** * 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); }
/** * 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; }
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); }
/** * @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); }
/** * 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)); }
/** * @dataProvider isValidAddMessagesCallDataProvider * * @param array $value * @param bool $hasEmptyColumns * @param array $customerGroups * @param array $expectedMessages */ public function testIsValidAddMessagesCall($value, $hasEmptyColumns, $customerGroups, $expectedMessages) { $priceContextMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], ['\\Magento\\Framework\\Json\\Helper\\Data', '\\Magento\\ImportExport\\Helper\\Data', '\\Magento\\ImportExport\\Model\\ResourceModel\\Import\\Data', '\\Magento\\Eav\\Model\\Config', '\\Magento\\Framework\\App\\ResourceConnection', '\\Magento\\ImportExport\\Model\\ResourceModel\\Helper', '\\Magento\\Framework\\Stdlib\\StringUtils', 'ProcessingErrorAggregatorInterface'], '', false); $this->tierPrice->expects($this->once())->method('isValidValueAndLength')->willReturn(true); $this->tierPrice->expects($this->any())->method('hasEmptyColumns')->willReturn($hasEmptyColumns); $this->setPropertyValue($this->tierPrice, 'customerGroups', $customerGroups); $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($searchCriteria); $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false); $this->groupRepository->expects($this->any())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult); $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass(); $groupTest->expects($this->once())->method('getCode'); $groupTest->expects($this->any())->method('getId'); $groups = [$groupTest]; $groupSearchResult->expects($this->any())->method('getItems')->willReturn($groups); $this->tierPrice->init($priceContextMock); $this->tierPrice->isValid($value); }
public function testGetVisibleAvailableTokens() { $customerId = 1; $searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock(); $searchResult = $this->getMockForAbstractClass(PaymentTokenSearchResultsInterface::class); $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); $customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0); $visibilityFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, true, 1); $isActiveFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_ACTIVE, true, 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(); $date = $this->getMockBuilder('DateTime')->disableOriginalConstructor()->getMock(); $this->dateTimeFactory->expects(static::once())->method('create')->with("now", new \DateTimeZone('UTC'))->willReturn($date); $date->expects(static::once())->method('format')->with('Y-m-d 00:00:00')->willReturn('2015-01-01 00:00:00'); $this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $visibilityFilter, $isActiveFilter, $expiresAtFilter])->willReturnSelf(); $this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria); $this->paymentTokenRepository->expects(self::once())->method('getList')->with($searchCriteria)->willReturn($searchResult); $searchResult->expects(self::once())->method('getItems')->willReturn([$token]); static::assertEquals([$token], $this->paymentTokenManagement->getVisibleAvailableTokens($customerId)); }
public function testItAddsTheSkuAsSerchCriteria() { $this->mockSearchCriteriaBuilder->expects($this->once())->method('addFilter')->with('sku', '%test%', 'like'); $this->mockSearchResult->expects($this->once())->method('getItems')->willReturn([]); $this->productStatusAdapter->getProductStatusMatchingSku('test'); }
public function testModifyData() { $sourceData = ['1' => ['product' => [ProductAttributeInterface::CODE_PRICE => '19.99']]]; $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock); $this->productMock->expects($this->any())->method('getId')->willReturn(1); $this->productMock->expects($this->once())->method('getAttributeSetId')->willReturn(4); $this->productMock->expects($this->once())->method('getData')->with(ProductAttributeInterface::CODE_PRICE)->willReturn('19.9900'); $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock); $this->attributeGroupRepositoryMock->expects($this->any())->method('getList')->willReturn($this->searchCriteriaMock); $this->searchCriteriaMock->expects($this->once())->method('getItems')->willReturn([$this->attributeGroupMock]); $this->sortOrderBuilderMock->expects($this->once())->method('setField')->willReturnSelf(); $this->sortOrderBuilderMock->expects($this->once())->method('setAscendingDirection')->willReturnSelf(); $dataObjectMock = $this->getMock('\\Magento\\Framework\\Api\\AbstractSimpleObject', [], [], '', false); $this->sortOrderBuilderMock->expects($this->once())->method('create')->willReturn($dataObjectMock); $this->searchCriteriaBuilderMock->expects($this->any())->method('addFilter')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->once())->method('addSortOrder')->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock); $this->attributeRepositoryMock->expects($this->once())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultsMock); $this->eavAttributeMock->expects($this->any())->method('getAttributeGroupCode')->willReturn('product-details'); $this->eavAttributeMock->expects($this->once())->method('getApplyTo')->willReturn([]); $this->eavAttributeMock->expects($this->once())->method('getFrontendInput')->willReturn('price'); $this->eavAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn(ProductAttributeInterface::CODE_PRICE); $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->eavAttributeMock]); $this->storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('en_US'); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->currencyMock->expects($this->once())->method('toCurrency')->willReturn('19.99'); $this->currencyLocaleMock->expects($this->once())->method('getCurrency')->willReturn($this->currencyMock); $this->assertEquals($sourceData, $this->eav->modifyData([])); }