Unit Testing Mock Guzzle Response
Guzzle includes a mock handler that lets you provide a mock HTTP response. Docs are at http://docs.guzzlephp.org/en/latest/testing.html. Here's how you might use it in your unit test:

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;

/**
 * Test the getMembershipClasses method.
 */
public function testGetMembershipClasses() {

  $body = file_get_contents(__DIR__ . '/Mocks/membership-class.json');
  // This sets up the mock client to respond to the first request it gets
  // with an HTTP 200 containing your mock json body.
  $mock = new MockHandler([
    new Response(200, [], $body),
  ]);
  $handler = HandlerStack::create($mock);
  $this-&gt;mockHttp = new HttpClient(['handler' =&gt; $handler]);

  $anonymousWebServices = new AnonymousWebServices(
    $this-&gt;mockHttp,
    $this-&gt;mockState,
    $this-&gt;mockConfigFactory
  );

  $membership_classes = $anonymousWebServices-&gt;getMembershipClasses();
  $membership_classes = json_decode($membership_classes-&gt;getContent());

  $this-&gt;assertNotEmpty($membership_classes);
  foreach ($membership_classes as $membership_class) {
    $this-&gt;assertTrue($membership_class-&gt;IsActive === TRUE);

  }

}


You can queue multiple mock responses by adding them to your handler at creation time:

  $mock = new MockHandler([
    new Response(200, [], $body),
    new Response(400, [], 'Request malformed.'),
  ]);


Or you can add them after your client has already been instantiated, as long as you keep a reference to your mock handler around. If you have multiple test methods, this is a lot easier to read and maintain:

public function setUp() {
  $this-&gt;mockHandler = new MockHandler();
  $handler = HandlerStack::create($this-&gt;mockHandler);
  $this-&gt;mockHttp = new HttpClient(['handler' =&gt; $handler]);
}

public function testSomething() {
  $this-&gt;mockHandler-&gt;append(new Response(200, [], 'apples and bananas'));
  $responseBody = $this-&gt;mockHttp-&gt;get('http://example.com')-&gt;getBody();
  $this-&gt;assertEquals($responseBody, 'apples and bananas');
}