tienvx / laravel-pact-provider
Pact Provider integration for Laravel
v0.2.0
2024-04-01 17:25 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10|^11
- illuminate/http: ^10|^11
- illuminate/routing: ^10|^11
- illuminate/support: ^10|^11
- illuminate/validation: ^10|^11
Requires (Dev)
- orchestra/testbench: ^8.22
- phpunit/phpunit: ^10.1
- squizlabs/php_codesniffer: ^3.7.2
README
This Laravel Package allow testing Laravel project with Pact PHP. It support:
- Verify sending messages
- Set up provider state
- Tear down provider state
Installation
composer require tienvx/laravel-pact-provider
Documentation
Register State Handler
namespace App\StateHandler; use Tienvx\PactProvider\Attribute\AsStateHandler; use Tienvx\PactProvider\Model\StateValues; use Tienvx\PactProvider\StateHandler\SetUpInterface; use Tienvx\PactProvider\StateHandler\TearDownInterface; #[AsStateHandler(state: 'A user with id dcd79453-7346-4423-ae6e-127c60d8dd20 exists')] class UserHandler implements SetUpInterface, TearDownInterface { public function setUp(array $params): ?StateValues { return new StateValues([ 'id' => 123, ]); } public function tearDown(array $params): void { } }
app()->bind(UserHandler::class);
Register Message Dispatcher
namespace App\MessageDispatcher; use Tienvx\PactProvider\Attribute\AsMessageDispatcher; use Tienvx\PactProvider\Model\Message; use Tienvx\PactProvider\MessageDispatcher\DispatcherInterface; #[AsMessageDispatcher(description: 'User created message')] class UserDispatcher implements DispatcherInterface { public function dispatch(): ?Message { } }
app()->bind(UserDispatcher::class);