This page lists common issues or message you might run into while building out your tests with Guzzler.

Mock queue is empty

OutOfBoundsException: Mock queue is empty

This exception is thrown by Guzzle's mock handler when you have either not provided a response to return from the mock queue, or have run out of responses. When Guzzle returns a response from the mock handler, it removes that response from the queue entirely.


// In your tests
    ->willRespond(new Response(201, [], 'Success'));

// Code under test

In the example above, we added only 1 response to the queue before executing our code under test. Then in that code under test we might end up calling that URL twice.

// In your production code
$response = $this->client->get('/some-url');

// Later in your production code
$response2 = $this->client->get('/some-url');

Guzzler's Error Messages

In order to be helpful, Guzzler Expectations are serialized into a user-friendly list of filters that exist on a failed expectation. For example, the following Expectation

    ->withHeader('Auth', 'Some-key')
    ->withQuery(['first' => 'value', 'second' => 'another'])
    ->will(new Response(200));

Would be serialized to a string error in the console as

Method was expected to be called 1 times, actually called 0 times. 

Expectation: /a-url-for/querying
Headers:  {
    "Auth": "Some-key"
Query: (Exclusive: false){
    "first": "value",
    "second": "another"
Method:   GET
Last Updated: 6/20/2019, 5:31:28 AM