Ejemplo n.º 1
0
         expect($route->variables())->toBe(['baz' => false, 'paths' => false]);
     });
 });
 describe("->scope()", function () {
     it("gets/sets route scope", function () {
         $scope = new stdClass();
         $route = new Route();
         expect($route->scope($scope))->toBe($route);
         expect($route->scope())->toBe($scope);
     });
 });
 describe("->apply()", function () {
     it("applies middlewares", function () {
         $r = new Router();
         $route = $r->bind('foo/bar', function ($route) {
             return 'A';
         })->apply(function ($request, $response, $next) {
             return '1' . $next() . '1';
         })->apply(function ($request, $response, $next) {
             return '2' . $next() . '2';
         });
         $route = $r->route('foo/bar');
         $actual = $route->dispatch();
         expect($actual)->toBe('21A12');
     });
 });
 describe(".link()", function () {
     it("creates relative links", function () {
         $route = new Route(['pattern' => 'foo/{bar}']);
         $link = $route->link(['bar' => 'baz']);
         expect($link)->toBe('/foo/baz');
Ejemplo n.º 2
0
             return '2' . $next() . '2';
         });
         $route = $r->route('foo/foo');
         $actual = $route->dispatch();
         expect($actual)->toBe('1A1');
         $route = $r->route('bar/bar');
         $actual = $route->dispatch();
         expect($actual)->toBe('21A12');
     });
 });
 describe("->strategy()", function () {
     it("sets a strategy", function () {
         $r = $this->router;
         $mystrategy = function ($router) {
             $router->bind('foo/bar', function () {
                 return 'Hello World!';
             });
         };
         $r->strategy('mystrategy', $mystrategy);
         expect($r->strategy('mystrategy'))->toBe($mystrategy);
         $r->mystrategy();
         $route = $r->route('foo/bar');
         expect($route->pattern())->toBe('foo/bar');
     });
     it("unsets a strategy", function () {
         $r = $this->router;
         $mystrategy = function () {
         };
         $r->strategy('mystrategy', $mystrategy);
         expect($r->strategy('mystrategy'))->toBe($mystrategy);
         $r->strategy('mystrategy', false);