Example #1
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']];
 }
Example #2
0
 public function test_route_methods()
 {
     $router = new Router();
     $router->get('get', '_get');
     $router->head('head', '_head');
     $router->post('post', '_post');
     $router->put('put', '_put');
     $router->update('update', '_update');
     $router->patch('patch', '_patch');
     $router->delete('delete', '_delete');
     $router->options('options', '_options');
     $routes = $router->getRoutes();
     $this->assertEquals('_get', array_shift($routes)->getAction());
     $this->assertEquals('_head', array_shift($routes)->getAction());
     $this->assertEquals('_post', array_shift($routes)->getAction());
     $this->assertEquals('_put', array_shift($routes)->getAction());
     $this->assertEquals('_update', array_shift($routes)->getAction());
     $this->assertEquals('_patch', array_shift($routes)->getAction());
     $this->assertEquals('_delete', array_shift($routes)->getAction());
     $this->assertEquals('_options', array_shift($routes)->getAction());
 }