Download the PHP package wolfpack-it/laravel-gwt-plugin without Composer
On this page you can find all versions of the php package wolfpack-it/laravel-gwt-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wolfpack-it/laravel-gwt-plugin
More information about wolfpack-it/laravel-gwt-plugin
Files in wolfpack-it/laravel-gwt-plugin
Package laravel-gwt-plugin
Short Description A Behavior Driven Testing (GWT) plugin for your Laravel Tests
License MIT
Informations about the package laravel-gwt-plugin
Laravel Given-When-Then plugin
A Behavior Driven Testing (GWT) plugin for your Laravel Tests
Install
Usage / Example
Basically you extend your Test with the TestCase provided by this package, which allows you to use the package methods. See an example below:
Methods
The as
method
While testing, the Sanctum::actingAs or Passport::actingAs method may be used to authenticate a user.
To use this Authenticated user in the Given-When-Then methods you can use the
as(Authenticatable $user, ?string $injectAs = null)
method.
This Authenticatable is then added to the auto injection for the other methods.
In order to change the default Auth Provider (Sanctum), you can use the following static methods to change these settings.
As long as the guard is defined in the config/auth.php
and the Auth Provider class implements the actingAs
method:
The fake
method
While testing, you might need to mock some services like Mails or Events.
In order to do this within the plugins syntax you can use the fake(string $facade)
method.
Any facade which contains the fake
method can be used.
The throws
method
The throws method indicates that you're expecting a when action to throw an exception. The methods expect an exception class name (string) and optionally a exception message.
The given
method
Given describes the preconditions and initial state before the start of a test and allows for any pre-test setup that may occur.
The method expects a Closure / Callable as first parameter and uses the outcome (Return Type) to populate the pre-conditions in the scenarios parameters.
The callable can use conditions from previous given methods in a chain via auto injection.
The second argument is to help define as which key the param can be retrieved by the auto-injection.
When using two of the same types, this as
params can be very useful. Example
The when
method
When describes actions taken during a test. This method expects the same arguments as the given method.
Where the second param has a default value of 'response'
. The callable can use all conditions from the previous given methods as needed.
The then
method
Then describes the outcome resulting from actions taken in the when clause. This method only expects a Closure / Callable which can make the assertions necessary. Via auto-injection the method can use both the result of the previous when methods and the previous conditions of the given methods. This might be useful when trying to compare given data to the given response.
Good to know
Make sure your closures / callables implement return types, so that the auto-injection is able to identify which condition or response to map to which argument.
This package was created by Pascal van Gemert @ WolfpackIT. It got open-sourced and is now licensed under the MIT license.