本文整理汇总了PHP中Magento\Framework\Event\ManagerInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerInterface::expects方法的具体用法?PHP ManagerInterface::expects怎么用?PHP ManagerInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Event\ManagerInterface
的用法示例。
在下文中一共展示了ManagerInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProcessRelations
public function testProcessRelations()
{
$this->relationProcessorMock->expects($this->once())->method('processRelation')->with($this->salesModelMock);
$this->salesModelMock->expects($this->once())->method('getEventPrefix')->willReturn('sales_event_prefix');
$this->eventManagerMock->expects($this->once())->method('dispatch')->with('sales_event_prefix_process_relation', ['object' => $this->salesModelMock]);
$this->entityRelationComposite->processRelations($this->salesModelMock);
}
示例2: testGetHtmlTxnIdIsNull
public function testGetHtmlTxnIdIsNull()
{
$this->eventManagerMock->expects($this->once())->method('dispatch');
$this->transaction->setData('txn_id', 'test');
$this->assertEquals('test', $this->transaction->getHtmlTxnId());
$this->assertEquals(null, $this->transaction->getData('html_txn_id'));
}
示例3: testIsAvailable
/**
* @param bool $result
*
* @dataProvider dataProviderForTestIsAvailable
*/
public function testIsAvailable($result)
{
$storeId = 15;
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
$this->scopeConfigMock->expects($this->once())->method('getValue')->with('payment/' . Stub::STUB_CODE . '/active', ScopeInterface::SCOPE_STORE, $storeId)->willReturn($result);
$this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('payment_method_is_active'), $this->countOf(3));
$this->assertEquals($result, $this->payment->isAvailable($this->quoteMock));
}
示例4: testAfterSaveDispatchWithStore
public function testAfterSaveDispatchWithStore()
{
$this->designConfig->expects($this->exactly(2))->method('getScope')->willReturn('store');
$this->designConfig->expects($this->once())->method('getScopeId')->willReturn(1);
$this->storeManager->expects($this->once())->method('getStore')->with(1)->willReturn($this->store);
$this->eventManager->expects($this->once())->method('dispatch')->with('admin_system_config_changed_section_design', ['website' => '', 'store' => $this->store]);
$this->plugin->afterSave($this->repository, $this->designConfig);
}
示例5: testAssignData
public function testAssignData()
{
$data = new DataObject();
$paymentInfo = $this->getMock(InfoInterface::class);
$this->payment->setInfoInstance($paymentInfo);
$eventData = [AbstractDataAssignObserver::METHOD_CODE => $this, AbstractDataAssignObserver::MODEL_CODE => $paymentInfo, AbstractDataAssignObserver::DATA_CODE => $data];
$this->eventManagerMock->expects(static::exactly(2))->method('dispatch')->willReturnMap([['payment_method_assign_data_' . Stub::STUB_CODE, $eventData], ['payment_method_assign_data', $eventData]]);
$this->payment->assignData($data);
}
示例6: testUpdateAndGetTranslations
public function testUpdateAndGetTranslations()
{
$translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2'];
$this->eventManagerMock->expects($this->once())->method('dispatch');
$this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations);
$this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US');
$this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent');
$this->assertEquals($translations, $this->model->updateAndGetTranslations());
}
示例7: testSaveFailed
/**
* @expectedException \Exception
* @expectedExceptionMessage Expected Exception
* @throws \Exception
*/
public function testSaveFailed()
{
$this->modelMock->expects($this->any())->method('getEventPrefix')->will($this->returnValue('event_prefix'));
$this->modelMock->expects($this->any())->method('getEventObject')->will($this->returnValue('event_object'));
$this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock));
$exception = new \Exception('Expected Exception');
$this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception));
$this->connectionMock->expects($this->once())->method('beginTransaction');
$this->connectionMock->expects($this->once())->method('rollback');
$this->eventManagerMock->expects($this->once())->method('dispatch')->with('event_prefix_save_attribute_before', ['event_object' => $this->attribute, 'object' => $this->modelMock, 'attribute' => ['attribute']]);
$this->attribute->saveAttribute($this->modelMock, 'attribute');
}
示例8: testGetProductCollection
public function testGetProductCollection()
{
$reviewModel = $this->getMock('Magento\\Review\\Model\\Review', ['__wakeUp', 'getProductCollection'], [], '', false);
$productCollection = $this->getMock('Magento\\Review\\Model\\Resource\\Review\\Product\\Collection', ['addStatusFilter', 'addAttributeToSelect', 'setDateOrder'], [], '', false);
$reviewModel->expects($this->once())->method('getProductCollection')->will($this->returnValue($productCollection));
$this->reviewFactory->expects($this->once())->method('create')->will($this->returnValue($reviewModel));
$productCollection->expects($this->once())->method('addStatusFilter')->will($this->returnSelf());
$productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
$productCollection->expects($this->once())->method('setDateOrder')->will($this->returnSelf());
$this->managerInterface->expects($this->once())->method('dispatch')->will($this->returnSelf());
$this->assertEquals($productCollection, $this->rss->getProductCollection());
}
示例9: testGetProductsCollection
public function testGetProductsCollection()
{
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false);
$this->product->expects($this->once())->method('getCollection')->will($this->returnValue($productCollection));
$productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
$productCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
$productCollection->expects($this->once())->method('setOrder')->will($this->returnSelf());
$this->eventManager->expects($this->once())->method('dispatch')->with('rss_catalog_notify_stock_collection_select');
$this->stock->expects($this->once())->method('addLowStockFilter')->with($productCollection);
$products = $this->notifyStock->getProductsCollection();
$this->assertEquals($productCollection, $products);
}
示例10: 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());
}
示例11: testExecute
/**
* @param bool $noDiscount
* @param string $couponCode
* @param string $errorMessage
* @param string $actualCouponCode
* @dataProvider isApplyDiscountDataProvider
*/
public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
{
$quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false);
$create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false);
$paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]];
$this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap);
$objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]];
$this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap);
$this->eventManager->expects($this->any())->method('dispatch');
$data = ['coupon' => ['code' => $couponCode]];
$postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]];
$this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap);
$create->expects($this->once())->method('importPostData')->willReturnSelf();
$create->expects($this->once())->method('initRuleData')->willReturnSelf();
$create->expects($this->any())->method('getQuote')->willReturn($quote);
$address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$create->expects($this->once())->method('getBillingAddress')->willReturn($address);
$quote->expects($this->any())->method('isVirtual')->willReturn(true);
$this->request->expects($this->once())->method('has')->with('item')->willReturn(false);
$create->expects($this->once())->method('saveQuote')->willReturnSelf();
$this->session->expects($this->any())->method('getQuote')->willReturn($quote);
$item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']);
$quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
$item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
if (!$noDiscount) {
$quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
}
$errorMessageManager = __($errorMessage, $couponCode);
$this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode);
$this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf();
$this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf();
$this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute());
}
示例12: testToHtml
/**
* Run test toHtml method
*
* @param bool $customerId
* @return void
*
* @dataProvider dataProviderToHtml
*/
public function testToHtml($customerId)
{
$cacheData = false;
$idQueryParam = 'id-query-param';
$sessionId = 'session-id';
$this->additional->setData('cache_lifetime', 789);
$this->additional->setData('cache_key', 'cache-key');
$this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
$this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false);
// get cache
$this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true);
// save cache
$this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false);
$this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData);
$this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam);
$this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId);
// call protected _toHtml method
$sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false);
$this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock);
$sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId);
if ($customerId) {
$this->assertEquals('<span><a >Not you?</a></span>', $this->additional->toHtml());
} else {
$this->assertEquals('', $this->additional->toHtml());
}
}
示例13: testGeneralSave
public function testGeneralSave()
{
$customerId = 1;
$currentPassword = '1234567';
$customerEmail = 'customer@example.com';
$address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->getMockForAbstractClass();
$currentCustomerMock = $this->getCurrentCustomerMock($customerId, $address);
$newCustomerMock = $this->getNewCustomerMock($customerId, $address);
$currentCustomerMock->expects($this->any())->method('getEmail')->willReturn($customerEmail);
$this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($currentCustomerMock);
$this->validator->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
$this->request->expects($this->once())->method('isPost')->willReturn(true);
$this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['change_email'], ['change_email'], ['change_password'])->willReturnOnConsecutiveCalls(true, true, false);
$this->request->expects($this->once())->method('getPost')->with('current_password')->willReturn($currentPassword);
$this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($currentCustomerMock);
$this->customerRepository->expects($this->once())->method('save')->with($newCustomerMock)->willReturnSelf();
$this->customerExtractor->expects($this->once())->method('extract')->with('customer_account_edit', $this->request)->willReturn($newCustomerMock);
$this->emailNotification->expects($this->once())->method('credentialsChanged')->with($currentCustomerMock, $customerEmail, false)->willReturnSelf();
$newCustomerMock->expects($this->once())->method('getEmail')->willReturn($customerEmail);
$this->eventManager->expects($this->once())->method('dispatch')->with('customer_account_edited', ['email' => $customerEmail]);
$this->messageManager->expects($this->once())->method('addSuccess')->with(__('You saved the account information.'))->willReturnSelf();
$this->resultRedirect->expects($this->once())->method('setPath')->with('customer/account')->willReturnSelf();
$this->authenticationMock->expects($this->once())->method('authenticate')->willReturn(true);
$this->assertSame($this->resultRedirect, $this->model->execute());
}
示例14: testSubmit
public function testSubmit()
{
$orderData = [];
$isGuest = true;
$isVirtual = false;
$customerId = 1;
$quoteId = 1;
$quoteItem = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false);
$billingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$shippingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
$payment = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false);
$baseOrder = $this->getMock('Magento\\Sales\\Api\\Data\\OrderInterface', [], [], '', false);
$convertedBillingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false);
$convertedShippingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false);
$convertedPayment = $this->getMock('Magento\\Sales\\Api\\Data\\OrderPaymentInterface', [], [], '', false);
$convertedQuoteItem = $this->getMock('Magento\\Sales\\Api\\Data\\OrderItemInterface', [], [], '', false);
$addresses = [$convertedShippingAddress, $convertedBillingAddress];
$payments = [$convertedPayment];
$quoteItems = [$quoteItem];
$convertedItems = [$convertedQuoteItem];
$quote = $this->getQuote($isGuest, $isVirtual, $billingAddress, $payment, $customerId, $quoteId, $quoteItems, $shippingAddress);
$this->quoteValidator->expects($this->once())->method('validateBeforeSubmit')->with($quote);
$this->quoteAddressToOrder->expects($this->once())->method('convert')->with($shippingAddress, $orderData)->willReturn($baseOrder);
$this->quoteAddressToOrderAddress->expects($this->at(0))->method('convert')->with($shippingAddress, ['address_type' => 'shipping', 'email' => 'customer@example.com'])->willReturn($convertedShippingAddress);
$this->quoteAddressToOrderAddress->expects($this->at(1))->method('convert')->with($billingAddress, ['address_type' => 'billing', 'email' => 'customer@example.com'])->willReturn($convertedBillingAddress);
$this->quoteItemToOrderItem->expects($this->once())->method('convert')->with($quoteItem, ['parent_item' => null])->willReturn($convertedQuoteItem);
$this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment)->willReturn($convertedPayment);
$order = $this->prepareOrderFactory($baseOrder, $convertedBillingAddress, $addresses, $payments, $convertedItems, $quoteId, $convertedShippingAddress);
$this->orderManagement->expects($this->once())->method('place')->with($order)->willReturn($order);
$this->eventManager->expects($this->at(0))->method('dispatch')->with('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]);
$this->eventManager->expects($this->at(1))->method('dispatch')->with('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]);
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote);
$this->assertEquals($order, $this->model->submit($quote, $orderData));
}
示例15: testExecuteWithSuccessOrderSave
/**
* Test for execute method
*
* @return void
*/
public function testExecuteWithSuccessOrderSave()
{
$testData = $this->getExecuteWithSuccessOrderSaveTestData();
$redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
$paymentMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
$checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getRedirectUrl'])->getMock();
$resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
$redirectMock->expects($this->never())->method('setPath')->with('*/*/')->willReturn('redirect');
$this->formKeyValidatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
$this->resultRedirectFactoryMock->expects($this->never())->method('create')->willReturn($redirectMock);
$this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap($testData['objectManager.get']);
// call _expireAjax method
$this->expireAjaxFlowHasItemsFalse();
$this->requestMock->expects($this->atLeastOnce())->method('getPost')->willReturnMap($testData['request.getPost']);
$this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($testData['agreementsValidator.isValid'])->willReturn(true);
$this->quoteMock->expects($this->atLeastOnce())->method('getPayment')->willReturn($paymentMock);
$paymentMock->expects($this->once())->method('setQuote')->with($this->quoteMock);
$paymentMock->expects($this->once())->method('importData')->with($testData['payment.importData']);
$this->onepageMock->expects($this->once())->method('saveOrder');
$this->onepageMock->expects($this->once())->method('getCheckout')->willReturn($checkoutMock);
$checkoutMock->expects($this->once())->method('getRedirectUrl')->willReturn(null);
$this->eventManagerMock->expects($this->once())->method('dispatch')->withConsecutive($this->equalTo('checkout_controller_onepage_saveOrder'), $this->countOf(2));
$this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($resultJsonMock);
$resultJsonMock->expects($this->once())->method('setData')->with($testData['resultJson.setData'])->willReturnSelf();
$this->assertEquals($resultJsonMock, $this->controller->execute());
}