diff --git a/src/Tempest/Http/src/Delete.php b/src/Tempest/Http/src/Delete.php new file mode 100644 index 000000000..516c3d525 --- /dev/null +++ b/src/Tempest/Http/src/Delete.php @@ -0,0 +1,27 @@ +[] $middleware + */ + array $middleware = [], + ) { + parent::__construct( + uri: $uri, + method: Method::DELETE, + middleware: $middleware, + ); + } +} diff --git a/src/Tempest/Http/tests/Routing/Construction/RouteConfiguratorTest.php b/src/Tempest/Http/tests/Routing/Construction/RouteConfiguratorTest.php index 0dd7369d3..665fd0230 100644 --- a/src/Tempest/Http/tests/Routing/Construction/RouteConfiguratorTest.php +++ b/src/Tempest/Http/tests/Routing/Construction/RouteConfiguratorTest.php @@ -5,6 +5,7 @@ namespace Tempest\Http\Tests\Routing\Construction; use PHPUnit\Framework\TestCase; +use Tempest\Http\Delete; use Tempest\Http\Method; use Tempest\Http\Route; use Tempest\Http\RouteConfig; @@ -35,11 +36,13 @@ public function test_adding_static_routes(): void new Route('/1', Method::GET), new Route('/2', Method::POST), new Route('/3', Method::GET), + new Delete('/4'), ]; $this->subject->addRoute($routes[0]); $this->subject->addRoute($routes[1]); $this->subject->addRoute($routes[2]); + $this->subject->addRoute($routes[3]); $config = $this->subject->toRouteConfig(); @@ -54,6 +57,10 @@ public function test_adding_static_routes(): void '/2' => $routes[1], '/2/' => $routes[1], ], + 'DELETE' => [ + '/4' => $routes[3], + '/4/' => $routes[3], + ], ], $config->staticRoutes); $this->assertEquals([], $config->dynamicRoutes); $this->assertEquals([], $config->matchingRegexes); @@ -66,12 +73,14 @@ public function test_adding_dynamic_routes(): void new Route('/dynamic/{id}', Method::PATCH), new Route('/dynamic/{id}/view', Method::GET), new Route('/dynamic/{id}/{tag}/{name}/{id}', Method::GET), + new Delete('/dynamic/{id}'), ]; $this->subject->addRoute($routes[0]); $this->subject->addRoute($routes[1]); $this->subject->addRoute($routes[2]); $this->subject->addRoute($routes[3]); + $this->subject->addRoute($routes[4]); $config = $this->subject->toRouteConfig(); @@ -85,11 +94,15 @@ public function test_adding_dynamic_routes(): void 'PATCH' => [ 'c' => $routes[1], ], + 'DELETE' => [ + 'f' => $routes[4], + ], ], $config->dynamicRoutes); $this->assertEquals([ 'GET' => '#^(?|/dynamic(?|/([^/]++)(?|/view\/?$(*MARK:d)|/([^/]++)(?|/([^/]++)(?|/([^/]++)\/?$(*MARK:e)))|\/?$(*MARK:b))))#', 'PATCH' => '#^(?|/dynamic(?|/([^/]++)\/?$(*MARK:c)))#', + 'DELETE' => '#^(?|/dynamic(?|/([^/]++)\/?$(*MARK:f)))#', ], $config->matchingRegexes); } }