Example #1
0
             $route = new Route(['pattern' => 'post/{id:[0-9]{3}}']);
             $route->link(['id' => '1234']);
         };
         expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'1234'`."));
     });
     it("throws an exception when a an array is provided for a non repeatable parameter placeholder", function () {
         $closure = function () {
             $route = new Route(['pattern' => 'post/{id}']);
             $route->link(['id' => ['123', '456']]);
         };
         expect($closure)->toThrow(new RouterException("Expected `'id'` to not repeat, but received `[123,456]`."));
     });
     it("throws an exception when one element of an array doesn't match the capture pattern", function () {
         $closure = function () {
             $route = new Route(['pattern' => 'post[/{id:[0-9]{3}}]+']);
             $route->link(['id' => ['123', '456', '78']]);
         };
         expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'78'`."));
     });
 });
 describe("->dispatch()", function () {
     it("passes route as argument of the handler function", function () {
         $r = new Router();
         $r->get('foo/{var1}[/{var2}]', ['host' => '{subdomain}.{domain}.bar'], function ($route, $response) {
             return array_merge([$response], array_values($route->params));
         });
         $response = new stdClass();
         $route = $r->route('foo/25', 'GET', 'foo.biz.bar');
         $actual = $route->dispatch($response);
         expect($actual)->toBe([$response, 'foo', 'biz', '25', null]);
         $route = $r->route('foo/25/bar', 'GET', 'foo.biz.bar');