milroyfraser / pest-plugin-gwt
Given When Then(GWT) Plugin for Pest
Fund package maintenance!
nunomaduro
Patreon
www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L
Installs: 20 925
Dependents: 1
Suggesters: 0
Security: 0
Stars: 99
Watchers: 5
Forks: 4
Open Issues: 0
Requires
- php: ^8.2
- pestphp/pest: ^3.0
- pestphp/pest-plugin: ^3.0
Requires (Dev)
- pestphp/pest-dev-tools: ^3.0.0
This package is auto-updated.
Last update: 2024-10-26 08:13:33 UTC
README
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);
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.
- Explore the docs: pestphp.com/docs/plugins/creating-plugins »
- Follow us on Twitter: @pestphp »
- Join us on the Discord Server: discord.gg/bMAJv82 »
Pest was created by Nuno Maduro under the Sponsorware license. It got open-sourced and is now licensed under the MIT license.