/** * @covers Mapper::connect */ public function testConnect() { $mapper = new Mapper(); $mapper->connect('home_route', new Route('/', array('_controller' => 'sample', '_action' => 'index'))); $mapper->connect('to_index_route', new Route('/{_controller}', array('_action' => 'index'))); $mapper->connect('complete_route', new Route('/{_controller}/{_action}')); $this->assertCount(3, $mapper->getRoutes()); return $mapper; }
protected function loadMapperFromYaml($app, $file) { $mapper = new Mapper(); $routesList = $app['yaml']->load($file); foreach ($routesList as $rname => $rconf) { $defaults = isset($rconf['defaults']) ? $rconf['defaults'] : array(); $requirements = isset($rconf['requirements']) ? $rconf['requirements'] : array(); $type = isset($rconf['type']) ? $rconf['type'] : ''; $resourcePath = isset($rconf['resourcePath']) ? $rconf['resourcePath'] : ''; if (!array_key_exists('pattern', $rconf)) { throw new \InvalidArgumentException(sprintf('Runtime Error: Route pattern for "%s" route is missing.', $rname)); } $mapper->connect($rname, new Route($rconf['pattern'], $defaults, $requirements, $type, $resourcePath)); } return $mapper; }