Download the PHP package spatie/pest-expectations without Composer
On this page you can find all versions of the php package spatie/pest-expectations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spatie/pest-expectations
More information about spatie/pest-expectations
Files in spatie/pest-expectations
Package pest-expectations
Short Description A collection of handy custom Pest customisations
License MIT
Homepage https://github.com/spatie/pest-expectations
Informations about the package pest-expectations
A collection of handy custom Pest customizations
This repo contains custom expectations to be used in a Pest test suite.
It also contains various helpers to make testing with Pest easier. Imagine, you only want to run a test on GitHub Actions. You can use the whenGitHubActions
helper to do so.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
Usage
Once installed, you can use the helpers provided by this package.
Expectations
toPassWith
This expectation can be used to test if an invokable validation rule works correctly.
In this example, the $value
will be given to YourValidationRule
. The expectation will pass if your rule passed for the given value.
You can expect the your validation not to pass for the given value, by using Pest's not()
.
toFailWith
This expectation can be used to test if an invokable validation rule did not pass for a given value.
In this example, the $value
will be given to YourValidationRule
. The expectation will pass if your rule did not pass for the given value.
Optionally, you can also pass a message as the second argument. The expectation will pass is the validation rule return the given $message
.
toBeModel
Expect that a value is a model an equal to the passed model.
The expectation will only pass if both models are Eloquent models of the same class, with the same key.
toBeArrayOf
Expect that a value is an array of the specified value.
The specified value may be a class name or a class instance, or one of the following string values:
'string'
'int'
'float'
'bool'
'scalar'
'array'
'object'
'null'
toBeScheduled
Expect that a value is a scheduled job, command or invokable class. The timezone
parameter, if passed, will also check that the specified timezone was defined.
Optionally, you may pass a callback that accepts an Illuminate\Console\Scheduling\Event
or Illuminate\Console\Scheduling\CallbackEvent
instance, so you can run any assertion needed:
toHaveJsonApiPagination
Expect that a response has JSON:API pagination. Have a look at our package spatie/laravel-json-api-paginate to see how to add JSON:API pagination to your Laravel app.
Helpers
This package offers various helpers that you can tack on any test. Here's an example of the whenGitHubActions
helper. When tacked on to a test, the test will be skipped unless you're running it on GitHub Actions.
To use the helpers, you should call registerSpatiePestHelpers()
in your Pest.php
file.
These helpers are provided by this package:
whenConfig($configKey)
: only run the test when the given Laravel config key is setwhenEnvVar($envVarName)
: only run the test when the given environment variable is setwhenWindows
: the test will be skipped unless running on WindowswhenMac
: the test will be skipped unless running on macOSwhenLinux
: the test will be skipped unless running on LinuxwhenGitHubActions()
: the test will be skipped unless running on GitHub ActionsskipOnGitHubActions()
: the test will be skipped when running on GitHub ActionswhenPhpVersion($version)
: the test will be skipped unless running on the given PHP version, or higher. You can pass a version like8
or8.1
.
Assertions
This package also provides a set of custom assertions that you can use in your tests.
In your TestCase
class, you can use the CustomAssertions
trait and call the registerCustomAssertions
method in the setUp
method.
assertHasJsonApiPagination
Assert that a response has JSON:API pagination. Have a look at our package spatie/laravel-json-api-paginate to see how to add JSON:API pagination to your Laravel app.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Freek Van der Herten
- All Contributors
License
The MIT License (MIT). Please see License File for more information.