PHP code example of dbt / client-fake

1. Go to this page and download the library: Download dbt/client-fake 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/ */

    

dbt / client-fake example snippets


use Dbt\ClientFake\ClientFake;
use Dbt\ClientFake\Options\Options;

$clientFake = new ClientFake($app, new Options(
    service: MyService::class,
    base: 'https://my-service.com',
    // Or false if the API isn't versioned.
    version: 'v1',
    // Optional headers to add to all fake responses for use in testing.
    headers: ['X-My-Header' => 'some value'],
));

$clientFake->fake('my/endpoint', ['data' => 'some data']);

$clientFake->commit();
// or
$clientFake();

$service = resolve(MyService::class);

$response = $service->callMyEndpoint();

$this->assertSame(['data' => 'some data'], $response->json());
$this->assertSame('some value', $response->header('X-My-Header'));

$clientFake->withoutCatchall();

$clientFake->enable($booleanCondition);

$clientFake->enable($booleanCondition, function (SomeOtherService $service) {
    $service->doSomething();
});