Exemple #1
0
 public function test_group()
 {
     $router = new Router();
     $anotherRouter = $router->group();
     $this->assertTrue($anotherRouter instanceof IRouter);
     $this->assertTrue($router !== $anotherRouter);
 }
 /**
  * @param IContainer $container
  */
 public function __construct(IContainer $container)
 {
     parent::__construct();
     $this->setCallableInvoker(new CallableInvoker($container));
     $this->getRoutesMatcher()->getFiltersMatcher()->setFilterInvoker(new FilterInvoker($container));
     $this->getRoutesMatcher()->getParameterResolver()->setParameterResolverInvoker(new ParameterResolverInvoker($container));
 }
Exemple #3
0
 public function routes_provider()
 {
     $router = new Router();
     $router->get('/shop/{name}', 'foo');
     $router->get('/category/{name}/item/{id}/{alias?}', 'foo');
     $router->post('/category/{name}/item/{id}', 'bar');
     $router->delete('/country/{country}/city/{city}/{any}', 'foo');
     $router->delete('country/{country}/city/{city}/{any?}', 'bar');
     $router->put('yolo/{what}/swag/{huh?}', 'bar');
     $routes = $router->getRoutes();
     return [[$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category'), false, [], null], [$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category/foo/item/bar'), true, ['name' => 'foo', 'id' => 'bar', 'alias' => null], 'foo'], [$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category/foo/item/bar/swag'), true, ['name' => 'foo', 'id' => 'bar', 'alias' => 'swag'], 'foo'], [$routes, HttpRequestMethod::POST, new Url('http://foo.bar/category/foo/item/bar/swag'), false, [], null], [$routes, HttpRequestMethod::POST, new Url('http://foo.bar/category/foo/item/bar'), true, ['name' => 'foo', 'id' => 'bar'], 'bar'], [$routes, HttpRequestMethod::DELETE, new Url('http://foo.bar/country/foo/city/bar/yolo/swag'), true, ['country' => 'foo', 'city' => 'bar', 'any' => 'yolo/swag'], 'foo'], [$routes, HttpRequestMethod::DELETE, new Url('http://foo.bar/country/foo/city/bar'), true, ['country' => 'foo', 'city' => 'bar', 'any' => null], 'bar'], [$routes, HttpRequestMethod::PUT, new Url('yolo/foo/swag/bar'), true, ['what' => 'foo', 'huh' => 'bar'], 'bar'], [$routes, HttpRequestMethod::PUT, new Url('yolo/foo/swag'), true, ['what' => 'foo', 'huh' => null], 'bar']];
 }
 function it_runs(IInput $input, IOutput $output)
 {
     $router = new Router();
     $router->addFilter('filter', function () {
     });
     for ($i = 0; $i < 15; $i++) {
         $router->get('/some/path', 'value');
     }
     for ($i = 0; $i < 15; $i++) {
         $router->group()->get('/another/path', 'value');
     }
     $router->enableFilter('filter');
     $this->run($input, $output, $router);
 }
Exemple #5
0
 public function test_register_route_using_any_method()
 {
     $router = new Router();
     $this->assertNull($router->match(HttpRequestMethod::GET, new Url('/foo')));
     $this->assertNull($router->match(HttpRequestMethod::POST, new Url('/foo')));
     $this->assertNull($router->match(HttpRequestMethod::PUT, new Url('/foo')));
     $this->assertNull($router->match(HttpRequestMethod::PATCH, new Url('/foo')));
     $this->assertNull($router->match(HttpRequestMethod::UPDATE, new Url('/foo')));
     $this->assertNull($router->match(HttpRequestMethod::DELETE, new Url('/foo')));
     $router->any('/foo', 'method');
     $route = $router->match(HttpRequestMethod::GET, new Url('/foo'));
     $this->assertTrue($route instanceof IRoute);
     $this->assertEquals($route, $router->match(HttpRequestMethod::POST, new Url('/foo')));
     $this->assertEquals($route, $router->match(HttpRequestMethod::PUT, new Url('/foo')));
     $this->assertEquals($route, $router->match(HttpRequestMethod::PATCH, new Url('/foo')));
     $this->assertEquals($route, $router->match(HttpRequestMethod::UPDATE, new Url('/foo')));
     $this->assertEquals($route, $router->match(HttpRequestMethod::DELETE, new Url('/foo')));
 }