eventsauce/pest-utilities
Test utilities for EventSauce.
589,813
2
| Install | |
|---|---|
composer require eventsauce/pest-utilities |
|
| Latest Version: | 3.4.1 |
| PHP: | ^8.0 |
| License: | MIT |
| Last Updated: | Nov 25, 2023 |
| Links: | GitHub · Packagist |
Maintainer: frankdejonge
Code generation for EventSauce
composer require --dev eventsauce/pest-utilities
Usage
First, create a base test case, as described in the regular PHPUnit setup.
Next, use the base test case in your Pest tests:
use function EventSauce\EventSourcing\PestTooling\expectToFail;
use function EventSauce\EventSourcing\PestTooling\given;
use function EventSauce\EventSourcing\PestTooling\nothingShouldHaveHappened;
use function EventSauce\EventSourcing\PestTooling\when;
uses(YourBaseTestCase::class);
it('you can use the object-oriented interface', function () {
$this->given(
new ShoppingCartInitiated(),
)->when(function (ShoppingCart $cart): void {
$cart->addProduct(new ProductId('garlic sauce'), 250);
})->then(
new ProductAddedToCart(new ProductId('garlic sauce'), 250)
);
});
it('or the function based interface', function () {
given(new ShoppingCartInitiated());
when(function (ShoppingCart $cart): void {
$cart->checkout();
});
expectToFail(SorryCantCheckout::becauseThereAreNoProductsInCart());
nothingShouldHaveHappened();
});
it('or mix it all', function () {
given(new ShoppingCartInitiated())
->when(function (ShoppingCart $cart): void {
$cart->checkout();
});
expectToFail(SorryCantCheckout::becauseThereAreNoProductsInCart())
->nothingShouldHaveHappened();
});
it('can be used in a compact manner')
->given(new ShoppingCartInitiated())
->when(fn (ShoppingCart $cart) => $cart->add(new ProductId('garlic sauce'), 250))
->then(new ProductAddedToCart(new ProductId('garlic sauce'), 250))
->assertScenario(); // needed for a Pest bug
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
637,827,751
9,703
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
413,412,504
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
391,429,217
4,660