本文整理汇总了PHP中Magento\Framework\DataObject::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::expects方法的具体用法?PHP DataObject::expects怎么用?PHP DataObject::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DataObject
的用法示例。
在下文中一共展示了DataObject::expects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddFieldsToResponseSuccess
/**
* Test for addFieldsToResponse method
*
* @return void
*/
public function testAddFieldsToResponseSuccess()
{
$testData = $this->getAddFieldsToResponseSuccessTestData();
$observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
$orderPaymentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock();
$instanceMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost')->disableOriginalConstructor()->getMock();
$requestToAuthorizenetMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Request')->disableOriginalConstructor()->setMethods(['setControllerActionName', 'setIsSecure', 'getData'])->getMock();
$requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getControllerName'])->getMockForAbstractClass();
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$this->coreRegistryMock->expects($this->once())->method('registry')->with('directpost_order')->willReturn($orderMock);
$orderMock->expects($this->once())->method('getId')->willReturn($testData['order.getId']);
$orderMock->expects($this->once())->method('getPayment')->willReturn($orderPaymentMock);
$orderPaymentMock->expects($this->once())->method('getMethod')->willReturn($testData['orderPayment.getMethod']);
$this->paymentMock->expects($this->exactly(2))->method('getCode')->willReturn($testData['payment.getCode']);
$observerMock->expects($this->atLeastOnce())->method('getData')->willReturnMap($testData['observer.getData']);
$this->resultMock->expects($this->once())->method('getData')->willReturn($testData['result.getData']);
$orderMock->expects($this->atLeastOnce())->method('getIncrementId')->willReturn($testData['order.getIncrementId']);
$this->sessionMock->expects($this->once())->method('addCheckoutOrderIncrementId')->with($testData['session.addCheckoutOrderIncrementId']);
$this->sessionMock->expects($this->once())->method('setLastOrderIncrementId')->with($testData['session.setLastOrderIncrementId']);
$orderPaymentMock->expects($this->once())->method('getMethodInstance')->willReturn($instanceMock);
$instanceMock->expects($this->once())->method('generateRequestFromOrder')->with($orderMock)->willReturn($requestToAuthorizenetMock);
$this->actionMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
$requestMock->expects($this->once())->method('getControllerName')->willReturn($testData['request.getControllerName']);
$requestToAuthorizenetMock->expects($this->once())->method('setControllerActionName')->with($testData['requestToAuthorizenet.setControllerActionName']);
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
$storeMock->expects($this->once())->method('isCurrentlySecure')->willReturn($testData['store.isCurrentlySecure']);
$requestToAuthorizenetMock->expects($this->once())->method('setIsSecure')->with($testData['requestToAuthorizenet.setIsSecure']);
$requestToAuthorizenetMock->expects($this->once())->method('getData')->willReturn($testData['requestToAuthorizenet.getData']);
$this->resultMock->expects($this->once())->method('setData')->with($testData['result.setData']);
$this->addFieldsToResponseObserver->execute($observerMock);
}
示例2: testIsValidFailed
/**
* Testing \Magento\Framework\Validator\Entity\Properties::isValid with changed data and invoked setter
*/
public function testIsValidFailed()
{
$this->_object->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true));
$this->_object->expects($this->once())->method('getData')->with('attr1')->will($this->returnValue(1));
$this->_object->expects($this->once())->method('getOrigData')->with('attr1')->will($this->returnValue(2));
$validator = new \Magento\Framework\Validator\Entity\Properties();
$validator->setReadOnlyProperties(['attr1']);
$this->assertFalse($validator->isValid($this->_object));
}
示例3: testNoRoute
/**
* @covers \Magento\Cms\Observer\NoRouteObserver::execute
*/
public function testNoRoute()
{
$this->observerMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($this->eventMock);
$this->eventMock->expects($this->atLeastOnce())->method('getStatus')->willReturn($this->objectMock);
$this->objectMock->expects($this->atLeastOnce())->method('setLoaded')->with(true)->willReturnSelf();
$this->objectMock->expects($this->atLeastOnce())->method('setForwardModule')->with('cms')->willReturnSelf();
$this->objectMock->expects($this->atLeastOnce())->method('setForwardController')->with('index')->willReturnSelf();
$this->objectMock->expects($this->atLeastOnce())->method('setForwardAction')->with('noroute')->willReturnSelf();
$this->assertEquals($this->noRouteObserver, $this->noRouteObserver->execute($this->observerMock));
}
示例4: testAroundValidateWithValidConfigurableProduct
/**
* @param $parentsIds
* @param $validationResult
* @param $runValidateAmount
* @param $result
* @dataProvider dataProviderForValidateWithValidConfigurableProduct
* @return void
*/
public function testAroundValidateWithValidConfigurableProduct($parentsIds, $validationResult, $runValidateAmount, $result)
{
$closureMock = function () {
return false;
};
$this->productMock->expects($this->once())->method('getId')->willReturn('product_id');
$this->configurableMock->expects($this->once())->method('getParentIdsByChild')->with('product_id')->willReturn($parentsIds);
$this->ruleMock->expects($this->exactly($runValidateAmount))->method('getConditions')->willReturn($this->ruleConditionsMock);
$this->ruleConditionsMock->expects($this->exactly($runValidateAmount))->method('validateByEntityId')->willReturnMap($validationResult);
$this->assertEquals($result, $this->validation->aroundValidate($this->ruleMock, $closureMock, $this->productMock));
}
示例5: testInitWithNonDecimalQty
public function testInitWithNonDecimalQty()
{
$quoteItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false);
$this->productMock->expects($this->once())->method('getId')->will($this->returnSelf());
$this->productMock->expects($this->never())->method('setIsQtyDecimal');
$this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf());
$this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10));
$this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf());
$this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock));
$this->assertInstanceOf('Magento\\Quote\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock));
}
示例6: testRender
/**
* @param bool $editable
* @param bool $onlyEdit
* @param string $expectedResult
* @return void
* @dataProvider renderDataProvider
*/
public function testRender($editable, $onlyEdit, $expectedResult)
{
$value = 'some value';
$keyValue = 'key';
$this->columnMock->expects($this->once())->method('getEditable')->willReturn($editable);
$this->columnMock->expects($this->any())->method('getEditOnly')->willReturn($onlyEdit);
$this->columnMock->expects($this->any())->method('getIndex')->willReturn($keyValue);
$this->columnMock->expects($this->any())->method('getId')->willReturn('test');
$this->dataObjectMock->expects($this->any())->method('getData')->with($keyValue)->willReturn($value);
$this->renderer->setColumn($this->columnMock);
$this->assertEquals($expectedResult, $this->renderer->render($this->dataObjectMock));
}
示例7: testNoCookies
/**
* @covers \Magento\Cms\Observer\NoCookiesObserver::execute
* @param string $pageUrl
* @dataProvider noCookiesDataProvider
*/
public function testNoCookies($pageUrl)
{
$pageId = 1;
$this->observerMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($this->eventMock);
$this->eventMock->expects($this->atLeastOnce())->method('getRedirect')->willReturn($this->objectMock);
$this->scopeConfigMock->expects($this->atLeastOnce())->method('getValue')->with('web/default/cms_no_cookies', 'store')->willReturn($pageId);
$this->cmsPageMock->expects($this->atLeastOnce())->method('getPageUrl')->with($pageId)->willReturn($pageUrl);
$this->objectMock->expects($this->any())->method('setRedirectUrl')->with($pageUrl)->willReturnSelf();
$this->objectMock->expects($this->any())->method('setRedirect')->with(true)->willReturnSelf();
$this->objectMock->expects($this->any())->method('setPath')->with('cookie/index/noCookies')->willReturnSelf();
$this->objectMock->expects($this->any())->method('setArguments')->with([])->willReturnSelf();
$this->assertEquals($this->noCookiesObserver, $this->noCookiesObserver->execute($this->observerMock));
}
示例8: testBeforeSave
public function testBeforeSave()
{
$regionId = '23';
$countryId = '67';
$this->object->expects($this->once())->method('getData')->with('region')->willReturn($regionId);
$this->object->expects($this->once())->method('getCountryId')->willReturn($countryId);
$this->regionFactory->expects($this->once())->method('create')->willReturn($this->region);
$this->region->expects($this->once())->method('load')->with($regionId)->willReturnSelf();
$this->region->expects($this->atLeastOnce())->method('getId')->willReturn($regionId);
$this->region->expects($this->once())->method('getCountryId')->willReturn($countryId);
$this->object->expects($this->once())->method('setRegionId')->with($regionId)->willReturnSelf();
$this->region->expects($this->once())->method('getName')->willReturn('Region name');
$this->object->expects($this->once())->method('setRegion')->with('Region name');
$this->model->beforeSave($this->object);
}
示例9: testAroundMap
public function testAroundMap()
{
$attrSetId = 333;
$expected = ['is_configurable' => 1];
/** @var \PHPUnit_Framework_MockObject_MockObject $attributeMapper */
$attributeMapper = $this->getMockBuilder('Magento\\Catalog\\Model\\Entity\\Product\\Attribute\\Group\\AttributeMapperInterface')->disableOriginalConstructor()->getMock();
/** @var \Magento\Eav\Model\Entity\Attribute|\PHPUnit_Framework_MockObject_MockObject $attribute */
$attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->getMock();
$proceed = function (Attribute $attribute) {
return [];
};
$this->attributeFactory->expects($this->once())->method('create')->will($this->returnValue($this->attribute));
$this->attribute->expects($this->once())->method('getUsedAttributes')->with($this->equalTo($attrSetId))->will($this->returnValue([$attrSetId]));
$attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attrSetId));
$this->registry->expects($this->once())->method('registry')->with($this->equalTo('current_attribute_set'))->will($this->returnValue($this->magentoObject));
$this->magentoObject->expects($this->once())->method('getId')->will($this->returnValue($attrSetId));
$result = $this->model->aroundMap($attributeMapper, $proceed, $attribute);
$this->assertEquals($expected, $result);
}
示例10: testAuthorize
/**
* Test method
* with resultCode = RESPONSE_CODE_APPROVED and Origresult != RESPONSE_CODE_FRAUDSERVICE_FILTER
*/
public function testAuthorize()
{
$this->initializationAuthorizeMock();
$this->buildRequestData();
$this->responseMock->expects($this->any())->method('getResultCode')->willReturn(Payflowpro::RESPONSE_CODE_APPROVED);
$this->responseMock->expects($this->any())->method('getOrigresult')->willReturn(0);
$this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($this->responseMock);
$this->responseValidator->expects($this->once())->method('validate')->with($this->responseMock);
$this->responseMock->expects($this->once())->method('getPnref')->willReturn('test-pnref');
$this->paymentMock->expects($this->once())->method('setTransactionId')->with('test-pnref')->willReturnSelf();
$this->paymentMock->expects($this->once())->method('setIsTransactionClosed')->with(0);
$this->assertSame($this->object, $this->object->authorize($this->paymentMock, 33));
}
示例11: testDisplayPriceAttribute
/**
* @param string $expected
* @param bool $dataObjectIsOrder
* @param bool $isCurrencyDifferent
* @param bool $magentoDataObjectHasOrder
* @param bool $strong
* @param string $separator
* @dataProvider displayPricesDataProvider
*/
public function testDisplayPriceAttribute($expected, $dataObjectIsOrder, $isCurrencyDifferent = true, $magentoDataObjectHasOrder = true, $strong = false, $separator = '<br/>')
{
$this->orderMock->expects($this->any())->method('isCurrencyDifferent')->will($this->returnValue($isCurrencyDifferent));
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
$this->priceCurrency->expects($this->any())->method('format')->will($this->returnValue('storeFormattedPrice'));
$dataObject = $this->orderMock;
if (!$dataObjectIsOrder) {
$returnRes = false;
if ($magentoDataObjectHasOrder) {
$returnRes = $this->orderMock;
}
$this->magentoObjectMock->expects($this->once())->method('getOrder')->will($this->returnValue($returnRes));
$this->magentoObjectMock->expects($this->any())->method('getData')->will($this->returnValue('data'));
$dataObject = $this->magentoObjectMock;
}
$this->assertEquals($expected, $this->adminHelper->displayPriceAttribute($dataObject, 'code', $strong, $separator));
}
示例12: buildRequestData
/**
* Build data for request for operation Authorize
*
* @return void
*/
protected function buildRequestData()
{
$this->paymentMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
$this->orderMock->expects($this->once())->method('getBillingAddress')->willReturn($this->addressBillingMock);
$this->orderMock->expects(static::once())->method('getId')->willReturn(1);
$this->orderMock->expects(static::once())->method('getIncrementId')->willReturn('0000001');
$this->orderMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressShippingMock);
$this->addressBillingMock->expects($this->once())->method('getFirstname')->willReturn('Firstname');
$this->addressBillingMock->expects($this->once())->method('getLastname')->willReturn('Lastname');
$this->addressBillingMock->expects($this->once())->method('getStreet')->willReturn(['street-1', 'street-2']);
$this->addressBillingMock->expects($this->once())->method('getCity')->willReturn('City');
$this->addressBillingMock->expects($this->once())->method('getRegionCode')->willReturn('RegionCode');
$this->addressBillingMock->expects($this->once())->method('getPostcode')->willReturn('Postcode');
$this->addressBillingMock->expects($this->once())->method('getCountryId')->willReturn('CountryId');
$this->orderMock->expects($this->once())->method('getCustomerEmail')->willReturn('customer@email.com');
$this->addressShippingMock->expects($this->once())->method('getFirstname')->willReturn('Firstname');
$this->addressShippingMock->expects($this->once())->method('getLastname')->willReturn('Lastname');
$this->addressShippingMock->expects($this->once())->method('getStreet')->willReturn(['street-1', 'street-2']);
$this->addressShippingMock->expects($this->once())->method('getCity')->willReturn('City');
$this->addressShippingMock->expects($this->once())->method('getRegionCode')->willReturn('RegionCode');
$this->addressShippingMock->expects($this->once())->method('getPostcode')->willReturn('Postcode');
$this->addressShippingMock->expects($this->once())->method('getCountryId')->willReturn('CountryId');
}
示例13: testGetTranslatedString
/**
* Test protected `getTranslatedString` method via public `getElementHtml` method
*/
public function testGetTranslatedString()
{
$this->configMock->expects($this->any())->method('getData')->withConsecutive(['enabled'])->willReturn(true);
$html = $this->model->getElementHtml();
$this->assertRegExp('/.*"Insert Image...":"Insert Image...".*/i', $html);
}
示例14: parentClass
/**
* @param \PHPUnit_Framework_MockObject_MockObject|DefaultType $group
* @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option $option
* @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest
* @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product
* @return void
*/
protected function parentClass($group, $option, $buyRequest, $product)
{
$group->expects($this->once())->method('setOption')->willReturnSelf();
$group->expects($this->once())->method('setProduct')->willReturnSelf();
$group->expects($this->once())->method('setRequest')->willReturnSelf();
$group->expects($this->once())->method('setProcessMode')->willReturnSelf();
$group->expects($this->once())->method('validateUserValue')->willReturnSelf();
$group->expects($this->once())->method('prepareForCart')->willReturn('someString');
$option->expects($this->once())->method('getType');
$option->expects($this->once())->method('groupFactory')->willReturn($group);
$option->expects($this->at(0))->method('getId')->willReturn(333);
$buyRequest->expects($this->once())->method('getData');
$buyRequest->expects($this->once())->method('getOptions');
$buyRequest->expects($this->once())->method('getSuperProductConfig')->willReturn([]);
$buyRequest->expects($this->any())->method('unsetData')->willReturnSelf();
$buyRequest->expects($this->any())->method('getQty');
$product->expects($this->once())->method('getOptions')->willReturn([$option]);
$product->expects($this->once())->method('getHasOptions')->willReturn(true);
$product->expects($this->once())->method('prepareCustomOptions');
$product->expects($this->any())->method('addCustomOption')->willReturnSelf();
$product->expects($this->any())->method('setCartQty')->willReturnSelf();
$product->expects($this->once())->method('setQty');
$this->catalogProduct->expects($this->once())->method('getSkipSaleableCheck')->willReturn(false);
}