Exemplo n.º 1
0
 public function test_filter_gets_invoked()
 {
     $routes = [new Route([HttpRequestMethod::GET], 'foo', 'handler')];
     $filter = new RouteFilter('foo', function () {
         return true;
     });
     $matcher = new RoutesMatcher();
     $matcher->getFiltersMatcher()->addFilter($filter);
     $route = $matcher->match($routes, HttpRequestMethod::GET, new Url('foo'));
     $this->assertNotNull($route);
     $matcher->getFiltersMatcher()->enableFilters(['foo']);
     $route = $matcher->match($routes, HttpRequestMethod::GET, new Url('foo'));
     $this->assertNotNull($route);
     $filter = new RouteFilter('foo', function () {
         return false;
     });
     $matcher->getFiltersMatcher()->addFilter($filter);
     $route = $matcher->match($routes, HttpRequestMethod::GET, new Url('foo'));
     $this->assertNotNull($route);
     $matcher->getFiltersMatcher()->enableFilters(['foo']);
     $route = $matcher->match($routes, HttpRequestMethod::GET, new Url('foo'));
     $this->assertNull($route);
 }
Exemplo n.º 2
0
 public function test_parameter_resolver_gets_invoked()
 {
     $routes = [new Route([HttpRequestMethod::GET], 'foo/{item}/{id}', 'handler')];
     $matcher = new RoutesMatcher();
     $resolver = new RouteResolver('item', function ($parameter) {
         return $parameter + 1;
     });
     $matcher->getParameterResolver()->addResolver($resolver);
     $route = $matcher->match($routes, HttpRequestMethod::GET, new Url('foo/10/20'));
     $this->assertNotNull($route);
     $this->assertEquals(11, $route->getParameter('item'));
     $this->assertEquals(20, $route->getParameter('id'));
 }