本文整理汇总了PHP中Magento\Framework\App\Request\Http::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::expects方法的具体用法?PHP Http::expects怎么用?PHP Http::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Request\Http
的用法示例。
在下文中一共展示了Http::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLog
/**
* @dataProvider logDataProvider
*/
public function testLog($logLevel, $method)
{
$message = 'Error message';
$this->request->expects($this->once())->method('getRequestUri')->willReturn($this->requestUri);
$this->psrLogger->expects($this->once())->method($method)->with($message . ' ' . $this->requestUri);
$this->logger->log($message, $logLevel);
}
示例2: testDispatchPostDispatch
public function testDispatchPostDispatch()
{
$this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME));
$this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME));
$expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock];
$this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true));
$this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false));
// _forward expectations
$this->_requestMock->expects($this->once())->method('initForward');
$this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams);
$this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME);
$this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME);
$this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME);
$this->_requestMock->expects($this->once())->method('setDispatched')->with(false);
// _redirect expectations
$this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams);
$this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false));
$this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters);
$this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock));
}
示例3: setUp
protected function setUp()
{
$orderId = 1;
$shipmentId = 1;
$shipment = [];
$tracking = [];
$this->shipmentLoaderMock = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false);
$this->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
$this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
$this->responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
$this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false);
$this->shipmentMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['__wakeup'], [], '', false);
$this->fileFactoryMock = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false);
$contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResponse', 'getSession', 'getActionFlag'], [], '', false);
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
$contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock));
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
$contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock));
$contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlag));
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
$this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
$this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
$this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
$this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
$this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
$this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\PrintPackage($contextMock, $this->shipmentLoaderMock, $this->fileFactoryMock);
}
示例4: testExecute
/**
* Run test execute method
*/
public function testExecute()
{
$orderId = 1;
$shipmentId = 1;
$shipment = [];
$tracking = [];
$result = 'result-html';
$layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['createBlock'], [], '', false);
$gridMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid', ['setIndex', 'toHtml'], [], '', false);
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
$this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
$this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
$this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
$this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
$this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
$this->shipmentLoaderMock->expects($this->once())->method('load');
$layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->will($this->returnValue($gridMock));
$this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
$this->responseMock->expects($this->once())->method('setBody')->with($result)->will($this->returnSelf());
$this->requestMock->expects($this->at(4))->method('getParam')->with('index');
$gridMock->expects($this->once())->method('setIndex')->will($this->returnSelf());
$gridMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
$this->assertNotEmpty('result-html', $this->controller->execute());
}
示例5: testProcess
/**
* @dataProvider processProvider
* @param bool $isPost
*/
public function testProcess($isPost)
{
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
if ($isPost) {
$publicCookieMetadataMock = $this->getMock('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata');
$publicCookieMetadataMock->expects($this->once())
->method('setPath')
->with('/')
->will($this->returnSelf());
$publicCookieMetadataMock->expects($this->once())
->method('setDuration')
->with(Version::COOKIE_PERIOD)
->will($this->returnSelf());
$publicCookieMetadataMock->expects($this->once())
->method('setHttpOnly')
->with(false)
->will($this->returnSelf());
$this->cookieMetadataFactoryMock->expects($this->once())
->method('createPublicCookieMetadata')
->with()
->will(
$this->returnValue($publicCookieMetadataMock)
);
$this->cookieManagerMock->expects($this->once())
->method('setPublicCookie');
}
$this->version->process();
}
示例6: testProcess
/**
* @dataProvider processProvider
* @param bool $isPost
*/
public function testProcess($isPost)
{
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
if ($isPost) {
$this->cookieMock->expects($this->once())->method('set');
}
$this->version->process();
}
示例7: testGetThemeByRequest
/**
* @param string $userAgent
* @param bool $useConfig
* @param bool|string $result
* @param array $expressions
* @dataProvider getThemeByRequestDataProvider
*/
public function testGetThemeByRequest($userAgent, $useConfig, $result, $expressions = [])
{
$this->requestMock->expects($this->once())->method('getServer')->with($this->equalTo('HTTP_USER_AGENT'))->will($this->returnValue($userAgent));
if ($useConfig) {
$this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))->will($this->returnValue(serialize($expressions)));
}
$this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock));
}
示例8: testGetScopeTitleDefault
public function testGetScopeTitleDefault()
{
$scope = 'default';
$scopeId = 0;
$scopeTypeName = 'Default';
$this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
$this->assertEquals($scopeTypeName, $this->block->getScopeTitle()->render());
}
示例9: testGetViewFileUrl
/**
* @param bool $isSecure
* @dataProvider getViewFileUrlDataProvider
*/
public function testGetViewFileUrl($isSecure)
{
$this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure));
$this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) {
return isset($value['_secure']) && $value['_secure'] === $isSecure;
}))->will($this->returnValue('result url'));
$this->assertEquals('result url', $this->model->getViewFileUrl('some file'));
}
示例10: 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());
}
示例11: testGetRequestUri
/**
* @param boolean $clean
* @param string $expectedValue
*
* @dataProvider getRequestUriDataProvider
*/
public function testGetRequestUri($clean, $expectedValue)
{
$this->_request->expects($this->once())->method('getRequestUri')->will($this->returnValue('value'));
$this->_prepareCleanString($clean);
$headerObject = $this->_objectManager->getObject('Magento\\Framework\\HTTP\\Header', ['httpRequest' => $this->_request, 'converter' => $this->_converter]);
$result = $headerObject->getRequestUri($clean);
$this->assertEquals($expectedValue, $result);
}
示例12: testPathDifferentiator
public function testPathDifferentiator()
{
$this->requestMock->method('isSecure')->willReturn(true);
$this->requestMock->expects($this->at(1))->method('getUriString')->willReturn('http://example.com/path/');
$this->requestMock->expects($this->at(4))->method('getUriString')->willReturn('http://example.com/path1/');
$this->contextMock->method('getVaryString')->willReturn(self::VARY);
$valuePath1 = $this->model->getValue();
$valuePath2 = $this->model->getValue();
$this->assertNotEquals($valuePath1, $valuePath2);
}
示例13: testExecuteWithWishlist
public function testExecuteWithWishlist()
{
$wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
$this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist);
$this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
$this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
$this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
$controller = $this->getController();
$controller->execute();
}
示例14: testExecutePageDirectAccess
public function testExecutePageDirectAccess()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
$this->request->expects($this->any())->method('getParams')->willReturn([]);
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null);
$resultRedirect = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->setMethods(['setPath'])->disableOriginalConstructor()->getMock();
$resultRedirect->expects($this->any())->method('setPath')->with('catalog/product/', ['_current' => true])->willReturnSelf();
$this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($resultRedirect);
$this->assertSame($resultRedirect, $this->object->execute());
}
示例15: testExecuteWithWishlist
public function testExecuteWithWishlist()
{
$url = 'http://redirect-url.com';
$quantity = 2;
$this->wishlistProviderMock->expects($this->once())->method('getWishlist')->willReturn($this->wishlistMock);
$this->requestMock->expects($this->any())->method('getParam')->with('qty')->willReturn($quantity);
$this->itemCarrierMock->expects($this->once())->method('moveAllToCart')->with($this->wishlistMock, 2)->willReturn($url);
$this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf();
$this->assertSame($this->resultRedirectMock, $this->allcartController->execute());
}