diff --git a/src/Handler/Router/Router.php b/src/Handler/Router/Router.php index c6c1d8e..084c77f 100644 --- a/src/Handler/Router/Router.php +++ b/src/Handler/Router/Router.php @@ -171,6 +171,15 @@ public static function convertQueryParam( ), ) : $value); + case $typeString === 'float': + return (float) (\is_array($value) + ? throw new \InvalidArgumentException( + \sprintf( + 'Query parameter `%s` must be an integer, array given.', + $queryName, + ), + ) + : $value); case $typeString === 'string': return (string) (\is_array($value) ? throw new \InvalidArgumentException( diff --git a/src/Module/Frontend/Module/Profiler/ApiController.php b/src/Module/Frontend/Module/Profiler/ApiController.php index 1c409ab..eb2b1ab 100644 --- a/src/Module/Frontend/Module/Profiler/ApiController.php +++ b/src/Module/Frontend/Module/Profiler/ApiController.php @@ -46,12 +46,21 @@ public function profilerTop(string $uuid, #[QueryParam] string $metric = ''): Me #[ AssertSuccess( Method::Get, - 'api/profiler/0190402f-7eb2-7287-82a8-897a0091f58e/call-graph', - ['uuid' => '0190402f-7eb2-7287-82a8-897a0091f58e'], + 'api/profiler/0190402f-7eb2-7287-82a8-897a0091f58e/call-graph?threshold=1.1&percentage=15.1&metric=wt', + [ + 'uuid' => '0190402f-7eb2-7287-82a8-897a0091f58e', + 'threshold' => 1.1, + 'percentage' => 15.1, + 'metric' => 'wt', + ], ), ] - public function profilerCallGraph(string $uuid): Message\CallGraph - { + public function profilerCallGraph( + string $uuid, + #[QueryParam] float $threshold = 1, + #[QueryParam] float $percentage = 15, + #[QueryParam] string $metric = 'wt' + ): Message\CallGraph { $event = $this->eventsStorage->get($uuid) ?? throw new \RuntimeException('Event not found.'); $event?->payload instanceof ProfilerPayload or throw new \RuntimeException('Invalid payload type.'); diff --git a/src/Module/Frontend/Service.php b/src/Module/Frontend/Service.php index 30c7ada..9dea1c0 100644 --- a/src/Module/Frontend/Service.php +++ b/src/Module/Frontend/Service.php @@ -90,7 +90,7 @@ public function smtpAttachments(string $uuid): Attachments|Success #[StaticRoute(Method::Delete, 'api/events')] #[ - AssertFail(Method::Delete, '/api/events'), + AssertSuccess(Method::Delete, '/api/events'), AssertFail(Method::Delete, 'api/events/'), AssertFail(Method::Delete, 'api/event'), ] @@ -117,9 +117,9 @@ public function eventsDelete(array $uuids = []): Success #[StaticRoute(Method::Get, 'api/events')] #[ + AssertSuccess(Method::Get, '/api/events'), AssertFail(Method::Get, 'api/event'), AssertFail(Method::Post, 'api/events'), - AssertFail(Method::Get, '/api/events'), ] public function eventsList(): EventCollection { @@ -131,7 +131,7 @@ public function eventsList(): EventCollection #[ AssertFail(Method::Get, 'api/setting'), AssertFail(Method::Post, 'api/settings'), - AssertFail(Method::Get, '/api/settings'), + AssertSuccess(Method::Get, '/api/settings'), ] public function settings(): Settings { diff --git a/tests/Unit/Handler/Router/RouterTest.php b/tests/Unit/Handler/Router/RouterTest.php index ef373cd..8f4e2f9 100644 --- a/tests/Unit/Handler/Router/RouterTest.php +++ b/tests/Unit/Handler/Router/RouterTest.php @@ -23,16 +23,16 @@ public static function routedClassesProvider(): iterable yield 'Frontend Event Assets' => [\Buggregator\Trap\Module\Frontend\Http\EventAssets::class]; } - #[StaticRoute(Method::Get, '/public-static-static-route')] + #[StaticRoute(Method::Get, 'public-static-static-route')] public static function publicStaticStaticRoute(): string { return 'public-static-static-route-result'; } - #[AssertRouteSuccess(Method::Delete, '/item/f00', ['uuid' => 'f00'])] - #[AssertRouteSuccess(Method::Delete, '/item/fzzzzzzzzz', ['uuid' => 'f'])] - #[AssertRouteFail(Method::Get, '/item/f00')] - #[RegexpRoute(Method::Delete, '#^/item/(?[a-f0-9-]++)#i')] + #[AssertRouteSuccess(Method::Delete, 'item/f00', ['uuid' => 'f00'])] + #[AssertRouteSuccess(Method::Delete, 'item/fzzzzzzzzz', ['uuid' => 'f'])] + #[AssertRouteFail(Method::Get, 'item/f00')] + #[RegexpRoute(Method::Delete, '#^item/(?[a-f0-9-]++)#i')] public static function publicStaticRegexpRoute(string $uuid): string { return $uuid; @@ -113,16 +113,16 @@ public function testArgumentsCollision(): void self::assertSame('123e4567-e89b-12d3-a456-426614174000', $route(uuid: 'no-pasaran')); } - #[StaticRoute(Method::Get, '/public-static-route')] + #[StaticRoute(Method::Get, 'public-static-route')] public function publicStaticRoute(): string { return 'public-static-route-result'; } #[AssertRouteSuccess(Method::Get, '/private-route')] + #[AssertRouteSuccess(Method::Get, 'private-route')] #[AssertRouteFail(Method::Post, '/private-route')] - #[AssertRouteFail(Method::Get, 'private-route')] - #[StaticRoute(Method::Get, '/private-route')] + #[StaticRoute(Method::Get, 'private-route')] private function privateRoute(): never { throw new \LogicException('This method should not be called.');