Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Libraries/Module/Templates/DemoApi/src/routes/routes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ return function ($route) {
$route->get('[:alpha:2]?/signout', 'AuthController', 'signout')->middlewares(['Signout']);
$route->get('[:alpha:2]?/my-posts', 'PostController', 'myPosts')->middlewares(['Editor']);
$route->post('[:alpha:2]?/my-posts/create', 'PostController', 'create')->middlewares(['Editor']);
$route->add('[:alpha:2]?/my-posts/amend/[id=:any]', 'PUT', 'PostController', 'amend')->middlewares(['Editor', 'Owner']);
$route->add('[:alpha:2]?/my-posts/delete/[id=:any]', 'DELETE', 'PostController', 'delete')->middlewares(['Editor', 'Owner']);
$route->add('[:alpha:2]?/my-posts/delete-image/[id=:any]', 'DELETE', 'PostController', 'deleteImage')->middlewares(['Editor', 'Owner']);
$route->post('[:alpha:2]?/account-settings/update', 'AccountController', 'update')->middlewares(['Update']);
$route->post('[:alpha:2]?/account-settings/update-password', 'AccountController', 'updatePassword')->middlewares(['Password']);
$route->put('[:alpha:2]?/my-posts/amend/[id=:any]', 'PostController', 'amend')->middlewares(['Editor', 'Owner']);
$route->delete('[:alpha:2]?/my-posts/delete/[id=:any]', 'PostController', 'delete')->middlewares(['Editor', 'Owner']);
$route->delete('[:alpha:2]?/my-posts/delete-image/[id=:any]', 'PostController', 'deleteImage')->middlewares(['Editor', 'Owner']);
$route->put('[:alpha:2]?/account-settings/update', 'AccountController', 'update')->middlewares(['Update']);
$route->put('[:alpha:2]?/account-settings/update-password', 'AccountController', 'updatePassword')->middlewares(['Password']);
})->middlewares(['Auth']);
};
20 changes: 20 additions & 0 deletions src/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ public function post(string $route, ...$params): Route
return $this->add($route, 'POST', ...$params);
}

/**
* @param string $route
* @param ...$params
* @return $this
*/
public function put(string $route, ...$params): Route
{
return $this->add($route, 'PUT', ...$params);
}

/**
* @param string $route
* @param ...$params
* @return $this
*/
public function delete(string $route, ...$params): Route
{
return $this->add($route, 'DELETE', ...$params);
}

/**
* Starts a named group of routes
* @param string $groupName
Expand Down
36 changes: 35 additions & 1 deletion tests/Unit/Router/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,40 @@ public function testPostRoute()
$this->assertCount(1, $this->route->getVirtualRoutes()['*']);
}

public function testPutRoute()
{
$this->assertEmpty($this->route->getRuntimeRoutes());

$this->assertEmpty($this->route->getVirtualRoutes()['*']);

$this->route->put('update', 'PostsController', 'update');

$this->assertIsArray($this->route->getRuntimeRoutes());

$this->assertIsArray($this->route->getVirtualRoutes());

$this->assertCount(1, $this->route->getRuntimeRoutes());

$this->assertCount(1, $this->route->getVirtualRoutes()['*']);
}

public function testDeleteRoute()
{
$this->assertEmpty($this->route->getRuntimeRoutes());

$this->assertEmpty($this->route->getVirtualRoutes()['*']);

$this->route->delete('delete', 'PostsController', 'delete');

$this->assertIsArray($this->route->getRuntimeRoutes());

$this->assertIsArray($this->route->getVirtualRoutes());

$this->assertCount(1, $this->route->getRuntimeRoutes());

$this->assertCount(1, $this->route->getVirtualRoutes()['*']);
}

public function testGroupRoute()
{
$this->route->group('auth', function ($route) {
Expand Down Expand Up @@ -191,7 +225,7 @@ public function testRoutesWithNames()
$this->assertEquals('first', $this->route->getRuntimeRoutes()[0]['name']);
}

public function testNamingRouteBeforeDefination()
public function testNamingRouteBeforeDefinition()
{
$this->expectException(RouteException::class);

Expand Down