public function url($urlOptions = array(), $name = null, $absolute = false)
 {
     if ($name === null) {
         $name = $this->request->get('_route');
     }
     return $this->router->generate($name, $urlOptions, $absolute);
 }
 /**
  * Tests the render() method when the route does not exist.
  *
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Renderer\ControllerRenderer::render()
  * @covers Cocur\Bundle\BuildBundle\Renderer\ControllerRenderer::getControllerName()
  * @covers Cocur\Bundle\BuildBundle\Renderer\ControllerRenderer::getRoute()
  *
  * @expectedException Cocur\Bundle\BuildBundle\Exception\RouteNotFoundException
  */
 public function renderShouldThrowExceptionIfRouteNotFound()
 {
     $this->nameParser->shouldReceive('parse')->once()->andReturn('Acme\\DemoBundle\\Controller\\DefaultController::indexAction');
     $routeCollection = m::mock('Symfony\\Component\\Routing\\RouteCollection');
     $routeCollection->shouldReceive('all')->once()->andReturn([]);
     $this->router->shouldReceive('getRouteCollection')->once()->andReturn($routeCollection);
     $this->renderer->render('AcmeDemoBundle:Default:index');
 }
 /**
  * Tests the renderByName() method, but the route is not found.
  *
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Renderer\RouteRenderer::renderByName()
  *
  * @expectedException Cocur\Bundle\BuildBundle\Exception\RouteNotFoundException
  */
 public function renderByNameShouldThrowExceptionIfRouteNotFound()
 {
     $route = m::mock('Symfony\\Component\\Routing\\Route');
     $routeCollection = m::mock('Symfony\\Component\\Routing\\RouteCollection');
     $routeCollection->shouldReceive('get')->with('invalid_route')->once()->andReturn(null);
     $this->router->shouldReceive('getRouteCollection')->once()->andReturn($routeCollection);
     $this->renderer->renderByName('invalid_route');
 }
 /**
  * Tests the render() method.
  *
  * Route collection returns two routes, one public and one private (prefixed with "_"), renderer
  * should only render the public route.
  *
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Renderer\RoutesRenderer::render()
  * @covers Cocur\Bundle\BuildBundle\Renderer\RoutesRenderer::getRoutes()
  */
 public function renderShouldRenderRoutesThatArePassedToTheConstructor()
 {
     $route = m::mock('Symfony\\Component\\Routing\\Route');
     $routeCollection = m::mock('Symfony\\Component\\Routing\\RouteCollection');
     $routeCollection->shouldReceive('get')->with('route1')->once()->andReturn($route);
     $this->router->shouldReceive('getRouteCollection')->once()->andReturn($routeCollection);
     $this->routeRenderer->shouldReceive('render')->with($route, 'route1')->once();
     $renderer = new RoutesRenderer($this->routeRenderer, $this->router, ['route1']);
     $result = $renderer->render();
     $this->assertEquals(1, $result);
 }
Ejemplo n.º 5
0
 /**
  * Gets the 'bigfoot_core.cmf_routing.router' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \Symfony\Component\Routing\Router A Symfony\Component\Routing\Router instance
  */
 protected function getBigfootCore_CmfRouting_RouterService()
 {
     $this->services['bigfoot_core.cmf_routing.router'] = $instance = new \Symfony\Component\Routing\Router($this->get('logger'));
     $instance->setContext($this->get('router.request_context'));
     return $instance;
 }