本文整理汇总了PHP中FOS\RestBundle\View\View::setRouteParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setRouteParameters方法的具体用法?PHP View::setRouteParameters怎么用?PHP View::setRouteParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\View\View
的用法示例。
在下文中一共展示了View::setRouteParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateResponseWithRoute
public function testCreateResponseWithRoute()
{
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get'));
$doRoute = function ($name, $parameters) {
$route = '/';
foreach ($parameters as $name => $value) {
$route .= sprintf('%s/%s/', $name, $value);
}
return $route;
};
$router = $this->getMockBuilder('Symfony\\Component\\Routing\\RouterInterface')->getMock();
$router->expects($this->any())->method('generate')->will($this->returnCallback($doRoute));
$container->expects($this->any())->method('get')->with('fos_rest.router')->will($this->returnValue($router));
$viewHandler = new ViewHandler(array('json' => false));
$viewHandler->setContainer($container);
$view = new View();
$view->setStatusCode(Codes::HTTP_CREATED);
$view->setRoute('foo');
$view->setRouteParameters(array('id' => 2));
$returnedResponse = $viewHandler->createResponse($view, new Request(), 'json');
$this->assertEquals('/id/2/', $returnedResponse->headers->get('location'));
}
示例2: testCreateResponseWithRoute
public function testCreateResponseWithRoute()
{
$doRoute = function ($name, $parameters) {
$route = '/';
foreach ($parameters as $name => $value) {
$route .= sprintf('%s/%s/', $name, $value);
}
return $route;
};
$this->router->expects($this->any())->method('generate')->will($this->returnCallback($doRoute));
$viewHandler = $this->createViewHandler(['json' => false]);
$view = new View();
$view->setStatusCode(Response::HTTP_CREATED);
$view->setRoute('foo');
$view->setRouteParameters(['id' => 2]);
$returnedResponse = $viewHandler->createResponse($view, new Request(), 'json');
$this->assertEquals('/id/2/', $returnedResponse->headers->get('location'));
}