PHP code example of tienvx / laravel-pact-provider

1. Go to this page and download the library: Download tienvx/laravel-pact-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tienvx / laravel-pact-provider example snippets



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);


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);