當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ManagerInterface::expects方法代碼示例

本文整理匯總了PHP中Magento\Framework\Message\ManagerInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP ManagerInterface::expects方法的具體用法?PHP ManagerInterface::expects怎麽用?PHP ManagerInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Message\ManagerInterface的用法示例。


在下文中一共展示了ManagerInterface::expects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTryToSaveInvalidDataShouldFailWithErrors

 public function testTryToSaveInvalidDataShouldFailWithErrors()
 {
     $validatorClass = 'Magento\\MediaStorage\\Model\\File\\Validator\\AvailablePath';
     $helperClass = 'Magento\\Sitemap\\Helper\\Data';
     $validPaths = [];
     $messages = ['message1', 'message2'];
     $sessionClass = 'Magento\\Backend\\Model\\Session';
     $data = ['sitemap_filename' => 'sitemap_filename', 'sitemap_path' => '/sitemap_path'];
     $siteMapId = 1;
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->requestMock->expects($this->once())->method('getParam')->with('sitemap_id')->willReturn($siteMapId);
     $validator = $this->getMock($validatorClass, [], [], '', false);
     $validator->expects($this->once())->method('setPaths')->with($validPaths)->willReturnSelf();
     $validator->expects($this->once())->method('isValid')->with('/sitemap_path/sitemap_filename')->willReturn(false);
     $validator->expects($this->once())->method('getMessages')->willReturn($messages);
     $helper = $this->getMock($helperClass, [], [], '', false);
     $helper->expects($this->once())->method('getValidPaths')->willReturn($validPaths);
     $session = $this->getMock($sessionClass, ['setFormData'], [], '', false);
     $session->expects($this->once())->method('setFormData')->with($data)->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with($validatorClass)->willReturn($validator);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([[$helperClass, $helper], [$sessionClass, $session]]);
     $this->messageManagerMock->expects($this->at(0))->method('addError')->withConsecutive([$messages[0]], [$messages[1]])->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('adminhtml/*/edit', ['sitemap_id' => $siteMapId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->saveController->execute());
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:25,代碼來源:SaveTest.php

示例2: testLoadCustomerQuoteThrowingException

 public function testLoadCustomerQuoteThrowingException()
 {
     $exception = new \Exception('Message');
     $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will($this->throwException($exception));
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Load customer quote error');
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->object->execute($observerMock);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:8,代碼來源:LoadCustomerQuoteObserverTest.php

示例3: testBeforeSaveFail

 public function testBeforeSaveFail()
 {
     $wrongValue = '/^mozillai';
     $this->regexp->setValue($wrongValue);
     $this->messageManager->expects($this->once())->method('addNotice')->with(__('Invalid regular expression: %value', ['value' => $wrongValue]));
     $this->regexp->beforeSave();
     $this->assertNull($this->regexp->getValue());
 }
開發者ID:ytorbyk,項目名稱:magento2-geo-store-switcher,代碼行數:8,代碼來源:RegexpTest.php

示例4: testDeleteActionNoId

 public function testDeleteActionNoId()
 {
     $this->requestMock->expects($this->once())->method('getParam')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('We can\'t find a synonym group to delete.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:8,代碼來源:DeleteTest.php

示例5: testAfterLogin

 /**
  * @return void
  */
 public function testAfterLogin()
 {
     $warningMessage = __('All other open sessions for this account were terminated.');
     $this->sessionsManager->expects($this->once())->method('processLogin');
     $this->sessionsManager->expects($this->once())->method('getCurrentSession')->willReturn($this->currentSession);
     $this->currentSession->expects($this->once())->method('isOtherSessionsTerminated')->willReturn(true);
     $this->messageManager->expects($this->once())->method('addWarning')->with($warningMessage);
     $this->model->afterLogin($this->authMock);
 }
開發者ID:dragonsword007008,項目名稱:magento2,代碼行數:12,代碼來源:AuthTest.php

示例6: testCheckConfig

 /**
  * Test case when module is enabled in config and php extension is installed
  *
  * @return void
  */
 public function testCheckConfig()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->newRelicWrapper->expects($this->once())->method('isExtensionInstalled')->willReturn(false);
     $this->config->expects($this->once())->method('disableModule');
     $this->messageManager->expects($this->once())->method('addError');
     $this->model->execute($eventObserver);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:15,代碼來源:CheckConfigTest.php

示例7: testSaveActionWithException

 public function testSaveActionWithException()
 {
     $this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
     $this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
     $this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
     $this->action->execute();
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:10,代碼來源:SaveTest.php

示例8: testExecute

 public function testExecute()
 {
     $ids = [1, 2];
     $this->request->expects($this->once())->method('getParam')->with('search')->will($this->returnValue($ids));
     $this->createQuery(0, 1);
     $this->createQuery(1, 2);
     $this->messageManager->expects($this->once())->method('addSuccess')->will($this->returnSelf());
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('search/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:10,代碼來源:MassDeleteTest.php

示例9: testExecuteRandom

 public function testExecuteRandom()
 {
     $newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
     $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
     $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
     $this->managerMock->expects($this->once())->method('addSuccessMessage');
     $this->managerMock->expects($this->once())->method('addNoticeMessage');
     $this->cacheMock->expects($this->once())->method('clean');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->model->execute();
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:11,代碼來源:SaveTest.php

示例10: testExecuteLocalizedException

 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecuteLocalizedException()
 {
     $phrase = new \Magento\Framework\Phrase('some error');
     $objectManager = new ObjectManager($this);
     $this->vault->expects($this->once())->method('processNonce')->willThrowException(new LocalizedException($phrase));
     $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'some error']);
     $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->messageManager->expects($this->once())->method('addError')->with($phrase);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\AjaxSave', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
     $this->assertSame($this->resultJson, $notification->execute());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:AjaxSaveTest.php

示例11: testExecute

 public function testExecute()
 {
     $message = "test";
     $flagMock = $this->getMockBuilder(\Magento\CatalogRule\Model\Flag::class)->setMethods(['getState'])->disableOriginalConstructor()->getMock();
     $eventObserverMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)->disableOriginalConstructor()->getMock();
     $eventObserverMock->expects($this->at(0))->method('getData')->with('dirty_rules')->willReturn($flagMock);
     $flagMock->expects($this->once())->method('getState')->willReturn(1);
     $eventObserverMock->expects($this->at(1))->method('getData')->with('message')->willReturn($message);
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with($message);
     $this->observer->execute($eventObserverMock);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:11,代碼來源:AddDirtyRulesNoticeTest.php

示例12: testEditActionBlockNoExists

 public function testEditActionBlockNoExists()
 {
     $blockId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId);
     $this->blockMock->expects($this->once())->method('load')->with($blockId);
     $this->blockMock->expects($this->once())->method('getId')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('This block no longer exists.'));
     $this->resultRedirectFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->editController->execute());
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:11,代碼來源:EditTest.php

示例13: testGetSectionData

 public function testGetSectionData()
 {
     $msgType = 'error';
     $msgText = 'All is lost';
     $msg = $this->getMockBuilder('Magento\\Framework\\Message\\MessageInterface')->getMock();
     $messages = [$msg];
     $msg->expects($this->once())->method('getType')->willReturn($msgType);
     $msg->expects($this->once())->method('getText')->willReturn($msgText);
     $msgCollection = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->getMock();
     $this->messageManager->expects($this->once())->method('getMessages')->with(true, null)->willReturn($msgCollection);
     $msgCollection->expects($this->once())->method('getItems')->willReturn($messages);
     $this->assertEquals(['messages' => [['type' => $msgType, 'text' => $msgText]]], $this->object->getSectionData());
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:13,代碼來源:MessagesTest.php

示例14: testExecuteInternalLocalizedException

 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecuteInternalLocalizedException()
 {
     $phrase = new \Magento\Framework\Phrase('Something went wrong while processing.');
     $objectManager = new ObjectManager($this);
     $this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase));
     $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']);
     $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->messageManager->expects($this->once())->method('addError')->with($phrase);
     $this->request->expects($this->any())->method('getParam')->willReturn(true);
     /** @var \Magento\Braintree\Controller\Creditcard\Generate $controller */
     $controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
     $this->assertSame($this->resultJson, $controller->executeInternal());
 }
開發者ID:nblair,項目名稱:magescotch,代碼行數:16,代碼來源:GenerateTest.php

示例15: testDeleteActionThrowsException

 public function testDeleteActionThrowsException()
 {
     $errorMsg = 'Can\'t delete the page';
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock);
     $this->pageMock->expects($this->once())->method('load')->with($this->pageId);
     $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title);
     $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg)));
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
開發者ID:tingyeeh,項目名稱:magento2,代碼行數:14,代碼來源:DeleteTest.php


注:本文中的Magento\Framework\Message\ManagerInterface::expects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。