当前位置: 首页>>代码示例>>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;未经允许,请勿转载。