本文整理汇总了PHP中Magento\Framework\Message\Manager::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::expects方法的具体用法?PHP Manager::expects怎么用?PHP Manager::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Message\Manager
的用法示例。
在下文中一共展示了Manager::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExecuteNotPost
public function testExecuteNotPost()
{
$this->validatorMock->expects($this->once())->method('validate')->willReturn(false);
$this->request->expects($this->once())->method('isPost')->willReturn(false);
$this->messageManager->expects($this->once())->method('addError')->with('You have not canceled the item.');
$this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
$this->assertEquals($this->resultRedirect, $this->controller->execute());
}
示例2: testExecute
public function testExecute()
{
$path = '*/*';
$this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
$this->messageManager->expects($this->once())->method('addSuccess')->with(__('We updated lifetime statistic.'));
$this->objectManager->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Resource\\Report\\Order')->willReturn($this->order);
$this->resultRedirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf();
$this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->refreshStatisticsController->execute());
}
示例3: testAfterDispatch
/**
* @param bool $isPost
* @param int $numOfCalls
* @dataProvider afterDispatchTestDataProvider
*/
public function testAfterDispatch($isPost, $numOfCalls)
{
$this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true));
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
$this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock));
$this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock));
$this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock));
$this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->will($this->returnValue($this->publicCookieMetadataMock));
$this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock);
$this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock));
}
示例4: testEditPostActionWithoutErrors
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditPostActionWithoutErrors()
{
$customerId = 24;
$address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
$loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
$loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
$this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
$this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
$this->request->expects($this->once())->method('isPost')->willReturn(true);
$this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
$this->customer->expects($this->once())->method('setId')->with($customerId);
$this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
$this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
$this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
$this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
$this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
$this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
$this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
$this->customerAccountManagement->expects($this->once())->method('changePassword');
$this->customerRepository->expects($this->once())->method('save');
$messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
$messageCollection->expects($this->once())->method('getCount')->willReturn(0);
$this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
$this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
$this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
$this->assertSame($this->redirectResultMock, $this->getController()->execute());
}
示例5: testEmail
public function testEmail()
{
$cmId = 10000031;
$cmManagement = 'Magento\Sales\Api\CreditmemoManagementInterface';
$cmManagementMock = $this->getMock($cmManagement, [], [], '', false);
$this->prepareRedirect($cmId);
$this->request->expects($this->once())
->method('getParam')
->with('creditmemo_id')
->willReturn($cmId);
$this->objectManager->expects($this->once())
->method('create')
->with($cmManagement)
->willReturn($cmManagementMock);
$cmManagementMock->expects($this->once())
->method('notify')
->willReturn(true);
$this->messageManager->expects($this->once())
->method('addSuccess')
->with('You sent the message.');
$this->assertInstanceOf(
'Magento\Backend\Model\View\Result\Redirect',
$this->creditmemoEmail->executeInternal()
);
$this->assertEquals($this->response, $this->creditmemoEmail->getResponse());
}
示例6: testEmail
public function testEmail()
{
$shipmentId = 1000012;
$orderId = 10003;
$tracking = [];
$shipment = ['items' => []];
$orderShipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', '__wakeup'], [], '', false);
$shipmentNotifierClassName = 'Magento\\Shipping\\Model\\ShipmentNotifier';
$shipmentNotifier = $this->getMock($shipmentNotifierClassName, ['notify', '__wakeup'], [], '', false);
$this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]]));
$this->shipmentLoader->expects($this->once())->method('setShipmentId')->with($shipmentId);
$this->shipmentLoader->expects($this->once())->method('setOrderId')->with($orderId);
$this->shipmentLoader->expects($this->once())->method('setShipment')->with($shipment);
$this->shipmentLoader->expects($this->once())->method('setTracking')->with($tracking);
$this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($orderShipment));
$orderShipment->expects($this->once())->method('save')->will($this->returnSelf());
$this->objectManager->expects($this->once())->method('create')->with($shipmentNotifierClassName)->will($this->returnValue($shipmentNotifier));
$shipmentNotifier->expects($this->once())->method('notify')->with($orderShipment)->will($this->returnValue(true));
$this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the shipment.');
$path = '*/*/view';
$arguments = ['shipment_id' => $shipmentId];
$this->prepareRedirect($path, $arguments, 0);
$this->shipmentEmail->execute();
$this->assertEquals($this->response, $this->shipmentEmail->getResponse());
}
示例7: testExecuteAddSuccessCriticalException
/**
* Test execute add success critical exception
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteAddSuccessCriticalException()
{
$wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
$product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
$item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
$helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
$logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
$exception = new \Exception();
$logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
$helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
$wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
$wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
$wishlist->expects($this->once())->method('save')->willReturn(null);
$wishlist->expects($this->once())->method('getId')->willReturn(56);
$product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
$product->expects($this->once())->method('getName')->willReturn('Test name');
$this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
$this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
$this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
$item->expects($this->once())->method('load')->with(3)->willReturnSelf();
$item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
$this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
$this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
$this->request->expects($this->once())->method('getParams')->willReturn([]);
$this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
$this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
$this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
$this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
$this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
$this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
$this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
$this->assertSame($this->resultRedirectMock, $this->getController()->execute());
}
示例8: testExecuteLoadShipmentFail
/**
* Run test execute method (fail load shipment model)
*/
public function testExecuteLoadShipmentFail()
{
$this->shipmentLoaderMock->expects($this->once())->method('load')->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
$this->messageManagerMock->expects($this->once())->method('addError')->will($this->returnSelf());
$this->redirectSection();
$this->assertNull($this->controller->execute());
}
示例9: testEmailNoOrderId
public function testEmailNoOrderId()
{
$this->request->expects($this->once())
->method('getParam')
->with('order_id')
->will($this->returnValue(null));
$this->orderRepositoryMock->expects($this->once())
->method('get')
->with(null)
->willThrowException(
new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist'))
);
$this->messageManager->expects($this->once())
->method('addError')
->with('This order no longer exists.');
$this->actionFlag->expects($this->once())
->method('set')
->with('', 'no-dispatch', true)
->will($this->returnValue(true));
$this->resultRedirect->expects($this->once())
->method('setPath')
->with('sales/*/')
->willReturnSelf();
$this->assertInstanceOf(
'Magento\Backend\Model\View\Result\Redirect',
$this->orderEmail->executeInternal()
);
}
示例10: testExecuteWithException
public function testExecuteWithException()
{
$customersIds = [10, 11, 12];
$this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
$this->customerRepositoryMock->expects($this->any())->method('getById')->willThrowException(new \Exception('Some message.'));
$this->messageManagerMock->expects($this->once())->method('addError')->with('Some message.');
$this->massAction->execute();
}
示例11: testExecuteUpdateAction
public function testExecuteUpdateAction()
{
$orderId = 30;
$action = 'update';
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
$this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
$this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
$this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($this->orderMock);
$this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock);
$this->orderMock->expects($this->any())->method('getId')->willReturn($orderId);
$this->orderMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock);
$this->orderMock->expects($this->once())->method('save')->willReturnSelf();
$this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The payment update has been made.');
$this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
$this->paymentMock->expects($this->once())->method('update');
$result = $this->reviewPayment->execute();
$this->assertEquals($this->resultRedirectMock, $result);
}
示例12: testExecuteUpdateAction
public function testExecuteUpdateAction()
{
$orderId = 30;
$action = 'update';
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
$this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
$this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock);
$this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId);
$this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
$this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf();
$this->paymentMock->expects($this->once())->method('update');
$this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true);
$this->messageManagerMock->expects($this->once())->method('addSuccess');
$this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf();
$result = $this->reviewPayment->execute();
$this->assertEquals($this->resultRedirectMock, $result);
}
示例13: testException
/**
* Order throws exception while canceling
*/
public function testException()
{
$exception = new \Exception('Can not cancel');
$order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
$this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]);
$order1->expects($this->once())->method('canCancel')->willReturn(true);
$order1->expects($this->once())->method('cancel')->willThrowException($exception);
$this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel');
$this->massAction->execute();
}
示例14: testEmail
public function testEmail()
{
$invoiceId = 10000031;
$orderId = 100000030;
$invoiceClassName = 'Magento\Sales\Model\Order\Invoice';
$cmNotifierClassName = 'Magento\Sales\Api\InvoiceManagementInterface';
$invoice = $this->getMock($invoiceClassName, [], [], '', false);
$invoice->expects($this->once())
->method('getEntityId')
->willReturn($invoiceId);
$order = $this->getMock('Magento\Sales\Model\Order', [], [], '', false);
$order->expects($this->once())
->method('getId')
->willReturn($orderId);
$this->request->expects($this->once())
->method('getParam')
->with('invoice_id')
->willReturn($invoiceId);
$invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface')
->disableOriginalConstructor()
->getMock();
$invoiceRepository->expects($this->any())
->method('get')
->willReturn($invoice);
$this->objectManager->expects($this->at(0))
->method('create')
->with('Magento\Sales\Api\InvoiceRepositoryInterface')
->willReturn($invoiceRepository);
$invoice->expects($this->once())
->method('getOrder')
->willReturn($order);
$this->objectManager->expects($this->at(1))
->method('create')
->with($cmNotifierClassName)
->willReturn($this->invoiceManagement);
$this->invoiceManagement->expects($this->once())
->method('notify')
->with($invoiceId)
->willReturn(true);
$this->messageManager->expects($this->once())
->method('addSuccess')
->with('You sent the message.');
$this->resultRedirectFactory->expects($this->atLeastOnce())
->method('create')
->willReturn($this->resultRedirect);
$this->resultRedirect->expects($this->once())
->method('setPath')
->with('sales/invoice/view', ['order_id' => $orderId, 'invoice_id' => $invoiceId])
->willReturnSelf();
$this->assertInstanceOf('Magento\Backend\Model\View\Result\Redirect', $this->invoiceEmail->executeInternal());
}
示例15: testEmailNoOrderId
public function testEmailNoOrderId()
{
$orderClassName = 'Magento\\Sales\\Model\\Order';
$order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false);
$this->request->expects($this->once())->method('getParam')->with('order_id')->will($this->returnValue(null));
$this->objectManager->expects($this->at(0))->method('create')->with($orderClassName)->will($this->returnValue($order));
$order->expects($this->once())->method('load')->with(null)->will($this->returnSelf());
$this->messageManager->expects($this->once())->method('addError')->with('This order no longer exists.');
$this->actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->will($this->returnValue(true));
$this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
$this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->orderEmail->execute());
}