当前位置: 首页>>代码示例>>PHP>>正文


PHP View::setRouteParameters方法代码示例

本文整理汇总了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'));
 }
开发者ID:mgldev,项目名称:coffeetrack,代码行数:22,代码来源:ViewHandlerTest.php

示例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'));
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:18,代码来源:ViewHandlerTest.php


注:本文中的FOS\RestBundle\View\View::setRouteParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。