From b7a9490b9e1aa33394f9a9ef3a396f344ddfdf9d Mon Sep 17 00:00:00 2001 From: Vincenzo Petrucci Date: Sun, 26 Nov 2023 16:28:39 +0100 Subject: [PATCH] feat(methods): Remove function and argument. Use only get and post. The payload must be provided with the post argument / method --- src/Factory.php | 31 ++++++------------------------- src/Plugin.php | 16 ++++------------ 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index 8180396..b366369 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -71,43 +71,24 @@ public function duration(int $seconds): self return $this; } - /** - * Specifies that the test should be run using the given HTTP method. - */ - public function method(string $method): self - { - $method = strtolower($method); - - assert(in_array($method, ['get', 'post'], true), 'The method must be one of: get, post'); - - $this->method = $method; - - return $this; - } - /** * Force the test to use get method */ public function get(): self { - return $this->method('get'); - } + $this->method = 'get'; - /** - * Force the test to use post method - */ - public function post(): self - { - return $this->method('post'); + return $this; } /** - * Specifies the payload to send for the test, if any. + * Force the test to use post method * - * @param array $payload + * @param array $payload The payload to send with the POST request */ - public function payload(array $payload): self + public function post(array $payload): self { + $this->method = 'post'; $this->payload = $payload; return $this; diff --git a/src/Plugin.php b/src/Plugin.php index 63e83a0..f80ec9c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -56,23 +56,15 @@ public function handleArguments(array $arguments): array $run->concurrently((int) str_replace('--concurrency=', '', $argument)); } - if (str_starts_with($argument, '--method=')) { - $run->method(str_replace('--method=', '', $argument)); - } - if ($argument === '--get') { $run->get(); } - if ($argument === '--post') { - $run->post(); - } - - if (str_starts_with($argument, '--payload=')) { + if (str_starts_with($argument, '--post=')) { try { - $payload = (array) json_decode(str_replace('--payload=', '', $argument), + $payload = (array) json_decode(str_replace('--post=', '', $argument), true, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $e) { + } catch (\JsonException) { View::render('components.badge', [ 'type' => 'ERROR', 'content' => 'Invalid JSON payload. Please provide a valid JSON payload.'. @@ -81,7 +73,7 @@ public function handleArguments(array $arguments): array exit(0); } - $run->payload($payload); + $run->post($payload); } }