Expectation Chaining

You can add as many expectations as you need!. Imagine you develop a service to consume an api with authentication. First, you need to consume the OAuth endpoint to create your token, and then you can consume all other endpoints. So, to set up your mock with this authentication you need at least two expectations, one for authentication and one for any other endpoint. Take a look at the following.

use EasyHttp\MockBuilder\HttpMock;
use EasyHttp\MockBuilder\MockBuilder;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;

$builder = new MockBuilder();
// first expectation for authentication
$builder
    ->when()
        ->methodIs('POST')
        ->pathIs('/v1/oauth2/token')
    ->then()
        ->body('{ "access_token": "dG9rZW4=" }');

// expectation for other endpoint
$builder
    ->when()
        ->methodIs('POST')
        ->pathIs('/v1/catalogs/products')
    ->then()
        ->statusCode(201)
        ->json([
            'name' => 'My new product'
        ]);

To be more explicit, I put the oauth authentication endpoint first. However, no matter what is the order of these expectations, the behavior is exactly the same.