本文整理汇总了PHP中Magento\Sales\Model\Order\Creditmemo::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Creditmemo::expects方法的具体用法?PHP Creditmemo::expects怎么用?PHP Creditmemo::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Creditmemo
的用法示例。
在下文中一共展示了Creditmemo::expects方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSend
/**
* @param int $configValue
* @param bool|null $forceSyncMode
* @param bool|null $customerNoteNotify
* @param bool|null $emailSendingResult
* @dataProvider sendDataProvider
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
{
$comment = 'comment_test';
$address = 'address_test';
$configPath = 'sales_email/general/async_sending';
$this->creditmemoMock->expects($this->once())->method('setSendEmail')->with(true);
$this->globalConfig->expects($this->once())->method('getValue')->with($configPath)->willReturn($configValue);
if (!$configValue || $forceSyncMode) {
$addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
$this->addressRenderer->expects($this->any())->method('format')->with($addressMock, 'html')->willReturn($address);
$this->orderMock->expects($this->any())->method('getBillingAddress')->willReturn($addressMock);
$this->orderMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
$this->creditmemoMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn($customerNoteNotify);
$this->creditmemoMock->expects($this->any())->method('getCustomerNote')->willReturn($comment);
$this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'creditmemo' => $this->creditmemoMock, 'comment' => $customerNoteNotify ? $comment : '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $address, 'formattedBillingAddress' => $address]);
$this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn($emailSendingResult);
if ($emailSendingResult) {
$this->senderBuilderFactoryMock->expects($this->once())->method('create')->willReturn($this->senderMock);
$this->senderMock->expects($this->once())->method('send');
$this->senderMock->expects($this->once())->method('sendCopyTo');
$this->creditmemoMock->expects($this->once())->method('setEmailSent')->with(true);
$this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, ['send_email', 'email_sent']);
$this->assertTrue($this->sender->send($this->creditmemoMock));
} else {
$this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
$this->assertFalse($this->sender->send($this->creditmemoMock));
}
} else {
$this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
$this->assertFalse($this->sender->send($this->creditmemoMock));
}
}
示例2: testCollect
public function testCollect()
{
$this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock, $this->creditmemoItemMock]);
$this->creditmemoItemMock->expects($this->exactly(2))->method('getHasChildren')->willReturn(false);
$this->creditmemoItemMock->expects($this->exactly(2))->method('getBaseCost')->willReturn(10);
$this->creditmemoItemMock->expects($this->exactly(2))->method('getQty')->willReturn(2);
$this->creditmemoMock->expects($this->once())->method('setBaseCost')->with(40)->willReturnSelf();
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
}
示例3: testProcessRelations
public function testProcessRelations()
{
$this->creditmemoMock->expects($this->once())->method('getId')->willReturn('creditmemo-id-value');
$this->creditmemoMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->itemMock]);
$this->creditmemoMock->expects($this->exactly(2))->method('getComments')->willReturn([$this->commentMock]);
$this->itemMock->expects($this->once())->method('setParentId')->with('creditmemo-id-value')->willReturnSelf();
$this->itemResourceMock->expects($this->once())->method('save')->with($this->itemMock)->willReturnSelf();
$this->commentResourceMock->expects($this->once())->method('save')->with($this->commentMock)->willReturnSelf();
$this->relationProcessor->processRelation($this->creditmemoMock);
}
示例4: testInvoke
/**
* Run creditmemo mapper test
*
* @return void
*/
public function testInvoke()
{
$this->creditmemoMock->expects($this->once())->method('getData')->will($this->returnValue(['field-1' => 'value-1']));
$this->creditmemoMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$this->creditmemoItemMock]));
$this->creditmemoBuilderMock->expects($this->once())->method('populateWithArray')->with($this->equalTo(['field-1' => 'value-1']))->will($this->returnSelf());
$this->creditmemoItemMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->creditmemoItemMock))->will($this->returnValue('item-1'));
$this->creditmemoBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo(['item-1']))->will($this->returnSelf());
$this->creditmemoBuilderMock->expects($this->once())->method('create')->will($this->returnValue('data-object-with-creditmemo'));
$this->assertEquals('data-object-with-creditmemo', $this->creditmemoMapper->extractDto($this->creditmemoMock));
}
示例5: testCollect
/**
* @param array $creditmemoData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($creditmemoData, $expectedResults)
{
$roundingDelta = [];
//Set up weeeData mock
$this->weeeData->expects($this->once())->method('includeInSubtotal')->will($this->returnValue($creditmemoData['include_in_subtotal']));
//Set up invoice mock
/** @var \Magento\Sales\Model\Order\Invoice\Item[] $creditmemoItems */
$creditmemoItems = [];
foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
$creditmemoItems[$itemKey] = $this->getInvoiceItem($creditmemoItemData);
}
$this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
foreach ($creditmemoData['data_fields'] as $key => $value) {
$this->creditmemo->setData($key, $value);
}
$this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->creditmemo);
//verify invoice data
foreach ($expectedResults['creditmemo_data'] as $key => $value) {
$this->assertEquals($value, $this->creditmemo->getData($key), 'Creditmemo data field ' . $key . ' is incorrect');
}
//verify invoice item data
foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
$creditmemoItem = $creditmemoItems[$itemKey];
foreach ($itemData as $key => $value) {
if ($key == 'tax_ratio') {
$taxRatio = unserialize($creditmemoItem->getData($key));
$expectedTaxRatio = unserialize($itemData[$key]);
$this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
} else {
$this->assertEquals($value, $creditmemoItem->getData($key), 'Creditmemo item field ' . $key . ' is incorrect');
}
}
}
}
示例6: testCollect
public function testCollect()
{
$this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock);
$this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
$this->creditmemoItemMock->expects($this->once())->method('calcRowTotal')->willReturnSelf();
$this->creditmemoItemMock->expects($this->once())->method('getRowTotal')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setSubtotal')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setBaseSubtotal')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setSubtotalInclTax')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setBaseSubtotalInclTax')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with(2)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with(2)->willReturnSelf();
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
}
示例7: testCollect
/**
* @param array $orderData
* @param array $creditmemoData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($orderData, $creditmemoData, $expectedResults)
{
$roundingDelta = [];
//Set up order mock
foreach ($orderData['data_fields'] as $key => $value) {
$this->order->setData($key, $value);
}
//Set up creditmemo mock
/** @var \Magento\Sales\Model\Order\Creditmemo\Item[] $creditmemoItems */
$creditmemoItems = [];
foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
$creditmemoItems[$itemKey] = $this->getCreditmemoItem($creditmemoItemData);
}
$this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
$this->creditmemo->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoData['is_last']));
foreach ($creditmemoData['data_fields'] as $key => $value) {
$this->creditmemo->setData($key, $value);
}
$this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->creditmemo);
//verify invoice data
foreach ($expectedResults['creditmemo_data'] as $key => $value) {
$this->assertEquals($value, $this->creditmemo->getData($key));
}
//verify invoice item data
foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
$creditmemoItem = $creditmemoItems[$itemKey];
foreach ($itemData as $key => $value) {
$this->assertEquals($value, $creditmemoItem->getData($key));
}
}
}
示例8: testSendVirtualOrder
/**
* @param bool $isVirtualOrder
* @param int $formatCallCount
* @param string|null $expectedShippingAddress
* @dataProvider sendVirtualOrderDataProvider
*/
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
{
$billingAddress = 'address_test';
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
$this->creditmemoMock->expects($this->once())->method('setSendEmail')->with(true);
$this->globalConfig->expects($this->once())->method('getValue')->with('sales_email/general/async_sending')->willReturn(false);
$addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
$this->addressRenderer->expects($this->exactly($formatCallCount))->method('format')->with($addressMock, 'html')->willReturn($billingAddress);
$this->stepAddressFormat($addressMock, $isVirtualOrder);
$this->creditmemoMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn(true);
$this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'creditmemo' => $this->creditmemoMock, 'comment' => '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $expectedShippingAddress, 'formattedBillingAddress' => $billingAddress]);
$this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn(false);
$this->creditmemoResourceMock->expects($this->once())->method('saveAttribute')->with($this->creditmemoMock, 'send_email');
$this->assertFalse($this->sender->send($this->creditmemoMock));
}
示例9: testExecute
/**
* @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::execute
*/
public function testExecute()
{
$creditmemoId = 2;
$date = '2015-01-19_13-03-45';
$fileName = 'creditmemo2015-01-19_13-03-45.pdf';
$fileContents = 'pdf0123456789';
$this->prepareTestExecute($creditmemoId);
$this->objectManagerMock->expects($this->any())->method('create')->willReturnMap([['Magento\\Sales\\Model\\Order\\Creditmemo', [], $this->creditmemoMock], ['Magento\\Sales\\Model\\Order\\Pdf\\Creditmemo', [], $this->creditmemoPdfMock]]);
$this->creditmemoMock->expects($this->once())->method('load')->with($creditmemoId)->willReturnSelf();
$this->creditmemoPdfMock->expects($this->once())->method('getPdf')->with([$this->creditmemoMock])->willReturn($this->pdfMock);
$this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->willReturn($this->dateTimeMock);
$this->dateTimeMock->expects($this->once())->method('date')->with('Y-m-d_H-i-s')->willReturn($date);
$this->pdfMock->expects($this->once())->method('render')->willReturn($fileContents);
$this->fileFactoryMock->expects($this->once())->method('create')->with($fileName, $fileContents, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, 'application/pdf')->willReturn($this->responseMock);
$this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $this->printAction->execute());
}
示例10: testExecute
/**
* test execute method
*/
public function testExecute()
{
$this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
$this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
$this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
$this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
$this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
$this->titleMock->expects($this->exactly(2))->method('prepend')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
$this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
$this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
$this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
$this->resultPageMock->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfigMock));
$this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock);
$this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock);
$this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order')->willReturnSelf();
$this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
$this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute());
}
示例11: testExecute
/**
* test execute method
*/
public function testExecute()
{
$this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
$this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
$this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
$this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
$this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
$this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
$this->titleMock->expects($this->exactly(3))->method('add')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
$this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
$this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
$this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
$this->viewMock->expects($this->once())->method('loadLayout');
$this->viewMock->expects($this->once())->method('renderLayout');
$this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
$this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo('menu'))->will($this->returnValue($this->blockMenuMock));
$this->blockMenuMock->expects($this->once())->method('setActive')->with($this->equalTo('Magento_Sales::sales_order'));
$this->blockMenuMock->expects($this->once())->method('getMenuModel')->will($this->returnValue($this->modelMenuMock));
$this->modelMenuMock->expects($this->once())->method('getParentItems')->will($this->returnValue([$this->modelMenuItem]));
$this->modelMenuItem->expects($this->once())->method('getTitle')->will($this->returnValue('item-title'));
$this->assertNull($this->controller->execute());
}
示例12: testCollect
public function testCollect()
{
$this->creditmemoMock->expects($this->exactly(2))->method('setDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->exactly(2))->method('setBaseDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
$this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn(1);
$this->orderMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn(1);
$this->orderMock->expects($this->exactly(2))->method('getBaseShippingAmount')->willReturn(1);
$this->orderMock->expects($this->once())->method('getShippingAmount')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock);
$this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
$this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getDiscountRefunded')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(0);
$this->creditmemoItemMock->expects($this->once())->method('isLast')->willReturn(false);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getQty')->willReturn(1);
$this->creditmemoItemMock->expects($this->exactly(1))->method('setDiscountAmount')->willReturnSelf();
$this->creditmemoItemMock->expects($this->exactly(1))->method('setBaseDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->exactly(2))->method('roundPrice')->willReturnMap([[1, 'regular', true, 1], [1, 'base', true, 1]]);
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
}
示例13: testNotifyFail
/**
* Test case when email has not been sent
*/
public function testNotifyFail()
{
$this->creditmemo->expects($this->once())->method('getEmailSent')->will($this->returnValue(false));
$this->assertFalse($this->notifier->notify($this->creditmemo));
}