/** * Set up Controller object. */ protected function setUp() { parent::setUp(); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->_soapServerMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Server')->disableOriginalConstructor()->setMethods(['getApiCharset', 'generateUri', 'handle'])->getMock(); $this->_wsdlGeneratorMock = $this->getMockBuilder('Magento\\Webapi\\Model\\Soap\\Wsdl\\Generator')->disableOriginalConstructor()->setMethods(['generate'])->getMock(); $this->_requestMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Request')->disableOriginalConstructor()->setMethods(['getParams', 'getParam', 'getRequestedServices', 'getHttpHost'])->getMock(); $this->_requestMock->expects($this->any())->method('getHttpHost')->willReturn('testHostName.com'); $this->_responseMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Response')->disableOriginalConstructor()->setMethods(['clearHeaders', 'setHeader', 'sendResponse', 'getHeaders'])->getMock(); $this->_errorProcessorMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\ErrorProcessor')->disableOriginalConstructor()->setMethods(['maskException'])->getMock(); $this->_appStateMock = $this->getMock('Magento\\Framework\\App\\State', [], [], '', false); $localeResolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\Resolver')->disableOriginalConstructor()->setMethods(['getLocale'])->getMock(); $localeResolverMock->expects($this->any())->method('getLocale')->will($this->returnValue('en')); $this->_responseMock->expects($this->any())->method('clearHeaders')->will($this->returnSelf()); $this->_responseMock->expects($this->any())->method('getHeaders')->will($this->returnValue(new \Zend\Http\Headers())); $appconfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false); $objectManagerHelper->setBackwardCompatibleProperty($this->_requestMock, 'appConfig', $appconfig); $this->_soapServerMock->expects($this->any())->method('setWSDL')->will($this->returnSelf()); $this->_soapServerMock->expects($this->any())->method('setEncoding')->will($this->returnSelf()); $this->_soapServerMock->expects($this->any())->method('setReturnResponse')->will($this->returnSelf()); $pathProcessorMock = $this->getMock('Magento\\Webapi\\Controller\\PathProcessor', [], [], '', false); $areaListMock = $this->getMock('Magento\\Framework\\App\\AreaList', [], [], '', false); $areaMock = $this->getMock('Magento\\Framework\\App\\AreaInterface'); $areaListMock->expects($this->any())->method('getArea')->will($this->returnValue($areaMock)); $rendererMock = $this->getMockBuilder('Magento\\Framework\\Webapi\\Rest\\Response\\RendererFactory')->disableOriginalConstructor()->getMock(); $this->_soapController = new \Magento\Webapi\Controller\Soap($this->_requestMock, $this->_responseMock, $this->_wsdlGeneratorMock, $this->_soapServerMock, $this->_errorProcessorMock, $this->_appStateMock, $localeResolverMock, $pathProcessorMock, $rendererMock, $areaListMock); }
protected function setUp() { $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resourcePageMock = $this->getMockBuilder(PageResource::class)->disableOriginalConstructor()->setMethods(['getIdFieldName', 'checkIdentifier'])->getMock(); $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock(); $this->resourcesMock = $this->getMockBuilder(AbstractResource::class)->setMethods(['getIdFieldName', 'load', 'checkIdentifier'])->getMockForAbstractClass(); $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock); $this->resourcePageMock->expects($this->any())->method('getResources')->willReturn($this->resourcesMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject(Page::class, ['context' => $this->contextMock, 'resource' => $this->resourcesMock]); $objectManager->setBackwardCompatibleProperty($this->model, 'scopeConfig', $this->scopeConfigMock); }
protected function setUp() { $this->scopeConfigMock = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface', ['isSetFlag'], '', false); $context = $this->getMock('\\Magento\\Framework\\App\\Action\\Context', ['getRequest', 'getResponse', 'getView', 'getUrl', 'getRedirect', 'getMessageManager'], [], '', false); $this->urlMock = $this->getMock('\\Magento\\Framework\\UrlInterface', [], [], '', false); $this->messageManagerMock = $this->getMock('\\Magento\\Framework\\Message\\ManagerInterface', [], [], '', false); $this->requestMock = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getPostValue'], [], '', false); $this->redirectMock = $this->getMock('\\Magento\\Framework\\App\\Response\\RedirectInterface', [], [], '', false); $this->viewMock = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', [], [], '', false); $this->storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false); $this->transportBuilderMock = $this->getMock('\\Magento\\Framework\\Mail\\Template\\TransportBuilder', [], [], '', false); $this->inlineTranslationMock = $this->getMock('\\Magento\\Framework\\Translate\\Inline\\StateInterface', [], [], '', false); $this->dataPersistorMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\DataPersistorInterface')->getMockForAbstractClass(); $context->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $context->expects($this->any())->method('getResponse')->willReturn($this->getMock('\\Magento\\Framework\\App\\ResponseInterface', [], [], '', false)); $context->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock); $context->expects($this->any())->method('getUrl')->willReturn($this->urlMock); $context->expects($this->any())->method('getRedirect')->willReturn($this->redirectMock); $context->expects($this->once())->method('getView')->willReturn($this->viewMock); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectManagerHelper->getObject('\\Magento\\Contact\\Controller\\Index\\Post', ['context' => $context, 'transportBuilder' => $this->transportBuilderMock, 'inlineTranslation' => $this->inlineTranslationMock, 'scopeConfig' => $this->scopeConfigMock, 'storeManager' => $this->storeManagerMock]); $objectManagerHelper->setBackwardCompatibleProperty($this->controller, 'dataPersistor', $this->dataPersistorMock); }
protected function setUp() { $this->checkoutSessionMock = $this->getMock('\\Magento\\Checkout\\Model\\Session', [], [], '', false); $this->customerSessionMock = $this->getMock('\\Magento\\Customer\\Model\\Session', [], [], '', false); $orderFactoryMock = $this->getMock('\\Magento\\Sales\\Model\\OrderFactory', [], [], '', false); $eventManagerMock = $this->getMock('\\Magento\\Framework\\Event\\ManagerInterface', [], [], '', false); $scopeConfigMock = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false); $sessionMock = $this->getMock('\\Magento\\Framework\\Session\\Generic', [], [], '', false); $addressFactoryMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\AddressFactory', [], [], '', false); $toOrderMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address\\ToOrder', [], [], '', false); $toOrderAddressMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address\\ToOrderAddress', [], [], '', false); $toOrderPaymentMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Payment\\ToOrderPayment', [], [], '', false); $toOrderItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item\\ToOrderItem', [], [], '', false); $storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false); $paymentSpecMock = $this->getMock('\\Magento\\Payment\\Model\\Method\\SpecificationInterface', [], [], '', false); $this->helperMock = $this->getMock('\\Magento\\Multishipping\\Helper\\Data', [], [], '', false); $orderSenderMock = $this->getMock('\\Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderSender', [], [], '', false); $priceMock = $this->getMock('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface', [], [], '', false); $this->quoteRepositoryMock = $this->getMock('\\Magento\\Quote\\Api\\CartRepositoryInterface'); $this->filterBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\FilterBuilder', [], [], '', false); $this->searchCriteriaBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false); $this->addressRepositoryMock = $this->getMock('\\Magento\\Customer\\Api\\AddressRepositoryInterface', [], [], '', false); /** * This is used to get past _init() which is called in construct. */ $data['checkout_session'] = $this->checkoutSessionMock; $this->quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false); $this->customerMock = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null); $this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock); $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomerDataObject')->willReturn($this->customerMock); $this->totalsCollectorMock = $this->getMock('Magento\\Quote\\Model\\Quote\\TotalsCollector', [], [], '', false); $this->model = new \Magento\Multishipping\Model\Checkout\Type\Multishipping($this->checkoutSessionMock, $this->customerSessionMock, $orderFactoryMock, $this->addressRepositoryMock, $eventManagerMock, $scopeConfigMock, $sessionMock, $addressFactoryMock, $toOrderMock, $toOrderAddressMock, $toOrderPaymentMock, $toOrderItemMock, $storeManagerMock, $paymentSpecMock, $this->helperMock, $orderSenderMock, $priceMock, $this->quoteRepositoryMock, $this->searchCriteriaBuilderMock, $this->filterBuilderMock, $this->totalsCollectorMock, $data); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->cartExtensionFactoryMock = $this->getMock(\Magento\Quote\Api\Data\CartExtensionFactory::class, ['create'], [], '', false); $this->shippingAssignmentProcessorMock = $this->getMock(\Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::class, [], [], '', false); $objectManager->setBackwardCompatibleProperty($this->model, 'cartExtensionFactory', $this->cartExtensionFactoryMock); $objectManager->setBackwardCompatibleProperty($this->model, 'shippingAssignmentProcessor', $this->shippingAssignmentProcessorMock); }