Skip to content
Open
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
20 changes: 19 additions & 1 deletion src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@

namespace Pest\Stressless;

function stress(string $url): Factory
use Closure;
use Pest\PendingCalls\TestCall;

/**
* If passed two parameters, this function creates a test
* with the `stress` group. If only passed one parameter,
* it will perform a stress test on the given URL.
*/
function stress(string $description, ?Closure $test = null): Factory|TestCall
{
return func_num_args() > 1
? test($description, func_get_arg(1))->group('stress')
: visit($description);
}

/**
* Performs a stress test on the given URL.
*/
function visit(string $url): Factory
{
return Factory::make($url);
}
8 changes: 8 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public function __construct()
*/
public function handleArguments(array $arguments): array
{
if ($this->hasArgument('--stress', $arguments)) {
return $this->pushArgument('--group=stress', $this->popArgument('--stress', $arguments));
}

if ($this->hasArgument('--exclude-stress', $arguments)) {
return $this->pushArgument('--exclude-group=stress', $this->popArgument('--exclude-stress', $arguments));
}

if (! array_key_exists(1, $arguments)) {
return $arguments;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/StressTestFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use function Pest\Stressless\stress;

stress('the homepage', function (): void {
stress('example.com');

expect(test()->groups()[0])->toBe('stress');
});
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use function Pest\Stressless\stress;
use function Pest\Stressless\visit;

uses()->beforeEach(function (): void {
$this->stress = $_SERVER['stress'] ??= stress('example.com')
$this->stress = $_SERVER['stress'] ??= visit('example.com')
->concurrently(2)
->for(1)->second();

Expand Down
24 changes: 13 additions & 11 deletions tests/Unit/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,73 @@

declare(strict_types=1);

it('correctly use get method by default', function (): void {
use function Pest\Stressless\stress;

stress('correctly use get method by default', function (): void {
expect($this->stress->method())->toBe('get');
});

it('correctly sets the delete method', function (): void {
stress('correctly sets the delete method', function (): void {
$this->stress->delete();

expect($this->stress->method())->toBe('delete');
});

it('correctly sets the get method', function (): void {
stress('correctly sets the get method', function (): void {
$this->stress->get();

expect($this->stress->method())->toBe('get');
});

it('correctly sets the head method', function (): void {
stress('correctly sets the head method', function (): void {
$this->stress->head();

expect($this->stress->method())->toBe('head');
});

it('correctly sets the options method without payload', function (): void {
stress('correctly sets the options method without payload', function (): void {
$this->stress->options();

expect($this->stress->method())->toBe('options')
->and($this->stress->payload())->toBe([]);
});

it('correctly sets the options method with payload', function (): void {
stress('correctly sets the options method with payload', function (): void {
$this->stress->options(['foo' => 'bar']);

expect($this->stress->method())->toBe('options')
->and($this->stress->payload())->toBe(['foo' => 'bar']);
});

it('correctly sets the patch method without payload', function (): void {
stress('correctly sets the patch method without payload', function (): void {
$this->stress->patch();

expect($this->stress->method())->toBe('patch')
->and($this->stress->payload())->toBe([]);
});

it('correctly sets the patch method with payload', function (): void {
stress('correctly sets the patch method with payload', function (): void {
$this->stress->patch(['foo' => 'bar']);

expect($this->stress->method())->toBe('patch')
->and($this->stress->payload())->toBe(['foo' => 'bar']);
});

it('correctly sets the put method without payload', function (): void {
stress('correctly sets the put method without payload', function (): void {
$this->stress->put();

expect($this->stress->method())->toBe('put')
->and($this->stress->payload())->toBe([]);
});

it('correctly sets the put method with payload', function (): void {
stress('correctly sets the put method with payload', function (): void {
$this->stress->put(['foo' => 'bar']);

expect($this->stress->method())->toBe('put')
->and($this->stress->payload())->toBe(['foo' => 'bar']);
});

it('correctly sets the post method', function (): void {
stress('correctly sets the post method', function (): void {
$this->stress->post(['foo' => 'bar']);

expect($this->stress->method())->toBe('post')
Expand Down