public function testIndexRouteCorrected()
 {
     /* @var $parser ControllerParser */
     $parser = $this->serviceManager->get('parser');
     $classReflection = new ClassReflection(new NoIndexRouteController());
     $builder = new RouteConfigBuilder();
     $builder->addPart($parser->parseController($classReflection, 'noindex'));
     $expected = array('root' => array('type' => 'literal', 'options' => array('route' => '/root', 'defaults' => array('controller' => 'noindex', 'action' => 'index'), 'constraints' => null), 'may_terminate' => true, 'child_routes' => array('index' => array('type' => 'literal', 'options' => array('route' => '/index', 'defaults' => array('controller' => 'noindex', 'action' => 'index'), 'constraints' => null), 'may_terminate' => true), 'edit' => array('type' => 'literal', 'options' => array('route' => '/edit', 'defaults' => array('controller' => 'noindex', 'action' => 'edit'), 'constraints' => null), 'may_terminate' => true), 'remove' => array('type' => 'literal', 'options' => array('route' => '/remove', 'defaults' => array('controller' => 'noindex', 'action' => 'remove'), 'constraints' => null), 'may_terminate' => true))));
     $this->assertEquals($expected, $builder->toArray());
 }
 public function testChildNodesAdded()
 {
     /* @var $parser ControllerParser */
     $parser = $this->serviceManager->get('parser');
     $classReflection = new ClassReflection(new NamespacedController());
     $builder = new RouteConfigBuilder();
     $builder->addPart($parser->parseController($classReflection, 'namespaced'));
     $expected = array('root' => array('type' => 'segment', 'options' => array('route' => '/root/:id/:method', 'defaults' => array('controller' => 'namespaced', 'action' => 'index'), 'constraints' => array('id' => '\\d+', 'method' => '\\w+')), 'may_terminate' => true, 'child_routes' => array('index' => array('type' => 'segment', 'options' => array('route' => '/root/:id/:method', 'defaults' => array('controller' => 'nobase', 'action' => 'complete-definition-action'), 'constraints' => array('id' => '\\d+', 'method' => '\\w+')), 'may_terminate' => true), 'edit' => array('type' => 'literal', 'options' => array('route' => '/edit', 'defaults' => array('controller' => 'namespaced', 'action' => 'edit'), 'constraints' => null), 'may_terminate' => true), 'remove' => array('type' => 'literal', 'options' => array('route' => '/remove', 'defaults' => array('controller' => 'namespaced', 'action' => 'remove'), 'constraints' => null), 'may_terminate' => true))));
     $this->assertEquals($expected, $builder->toArray());
 }
 /**
  * Returns complete router config from parsed controllers.
  *
  * @return array
  */
 public function getRouteConfig()
 {
     $configBuilder = new RouteConfigBuilder();
     foreach ($this->controllers as $controllerAlias => $controller) {
         $classReflection = new ClassReflection($controller);
         $routes = $this->parseController($classReflection, $controllerAlias);
         $configBuilder->addPart($routes);
     }
     return $configBuilder->toArray();
 }
 public function testIndexRouteCorrected()
 {
     /* @var $parser ControllerParser */
     $parser = $this->serviceManager->get('parser');
     $classReflection = new ClassReflection(new ExtendsController());
     $builder = new RouteConfigBuilder();
     $builder->addPart($parser->parseController($classReflection, 'extends'));
     $routeConfig = $this->serviceManager->get('Config')['router']['routes'];
     $config = array_replace_recursive($builder->toArray(), $routeConfig);
     $expected = array('default' => array('type' => 'literal', 'options' => array('route' => '/'), 'child_routes' => array('help' => array('type' => 'literal', 'options' => array('route' => '/help'), 'child_routes' => array('root' => array('type' => 'literal', 'options' => array('route' => '/root', 'defaults' => array('controller' => 'extends', 'action' => 'index'), 'constraints' => null), 'may_terminate' => true, 'child_routes' => array('index' => array('type' => 'literal', 'options' => array('route' => '/index', 'defaults' => array('controller' => 'extends', 'action' => 'index'), 'constraints' => null), 'may_terminate' => true))))))));
     $this->assertEquals($expected, $config);
 }
 public function testAutodetectAction()
 {
     $configBuilder = new RouteConfigBuilder();
     /* @var $parser ControllerAnnotationParser */
     $parser = $this->serviceManager->get('parser');
     $classReflection = new ClassReflection(new NoBaseController());
     $method = $classReflection->getMethod('noActionAction');
     $annotations = $parser->getMethodAnnotations($method);
     /* @var $route Route */
     $route = $annotations[0];
     $parser->autodetectMissingFields($route, $method, 'controllerkey');
     $configBuilder->addPart($route);
     $routeArray = array('no-action' => array('type' => 'literal', 'options' => array('route' => '/no-action', 'defaults' => array('controller' => 'controllerkey', 'action' => 'no-action'), 'constraints' => null), 'may_terminate' => true));
     $this->assertEquals($routeArray, $configBuilder->toArray());
 }