Skip to content

Commit

Permalink
feat(methods): Remove function and argument. Use only get and post. T…
Browse files Browse the repository at this point in the history
…he payload must be provided with the post argument / method
  • Loading branch information
nahime0 committed Nov 26, 2023
1 parent 4b9e3da commit b7a9490
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 37 deletions.
31 changes: 6 additions & 25 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $payload
* @param array<string, mixed> $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;
Expand Down
16 changes: 4 additions & 12 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'.
Expand All @@ -81,7 +73,7 @@ public function handleArguments(array $arguments): array

exit(0);
}
$run->payload($payload);
$run->post($payload);
}
}

Expand Down

0 comments on commit b7a9490

Please sign in to comment.