New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

milroyfraser/pest-plugin-gwt

Given When Then(GWT) Plugin for Pest
33,699 107
Install
composer require milroyfraser/pest-plugin-gwt
Latest Version:v2.0.0
PHP:^8.2
License:MIT
Last Updated:Sep 26, 2024
Links: GitHub  ·  Packagist
Maintainer: milroy.me

Given When Then (GWT) Plugin for Pest

A simple API allows you to structure your tests focused on the behaviour. Given-When-Then separation makes the test easier to understand at a glance.

Install

composer require milroyfraser/pest-plugin-gwt --dev

Usage

use App\Exceptions\BlockedUserException;
use App\Models\User;
use function Pest\Gwt\scenario;
use function Pest\Laravel\assertDatabaseHas;

scenario('activate user')
    ->given(fn() => User::factory()->create())
    ->when(fn(User $user) => $user->activate())
    ->then(fn(User $user) => assertDatabaseHas('users', [
        'id' => $user->id,
        'activated' => true,
    ]));

scenario('activate blocked user')
    ->given(fn() => User::factory()->blocked()->create())
    ->when(fn(User $user) => $user->activate())
    ->throws(BlockedUserException::class);

more examples

Given a state

Given method accepts a Closure. This is where we Arrange application state. The return values will become argument/s of the when closure.

When I do something

When method accepts a Closure. This is where we Act (perform) the operation. The return values will become argument/s of the then closure.

Then I expect an outcome

Then method accepts a Closure. This is where we Assert the outcome.

If you want to start testing your application with Pest, visit the main Pest Repository.

Pest was created by Nuno Maduro under the Sponsorware license. It got open-sourced and is now licensed under the MIT license.

Related Packages

pestphp/pest-plugin-stressless

Stressless plugin for Pest

1,358,012 67
erikgaal/pest-plugin-sharding

Pest Plugin to split tests into multiple runs

614,369 2
lukeraymonddowning/pest-plugin-money

A Pest PHP plugin that makes testing popular Money packages easy.

69,939 21

Version History

Version Released PHP License
v2.0.0 ^8.2 MIT
1.0.0 ^8.1 MIT
0.0.3 ^7.3 || ^8.0 MIT
0.0.2 ^7.3 || ^8.0 MIT