title: How to mock responses for specific URLs with Guzzle?
body: <p>The Guzzle 6 documentation gives an easy way to mock HTTP calls so that each request returns a specific response : <a href="http://docs.guzzlephp.org/en/latest/testing.html#mock-handler" rel="noreferrer">http://docs.guzzlephp.org/en/latest/testing.html#mock-handler</a></p>
  
  <p>However, as it is stated in the documentation, the <code>MockHandler</code> defines a queue of responses that will be sent for each request, whatever the URL, in the same order.</p>
  
  <p>How to tell Guzzle to send a specific response for a given URL, each time it is called?</p>
  
  <p>For instance, I want this call:</p>
  
  <pre><code>$client-&gt;request('GET', '/products')-&gt;getBody();
  </code></pre>
  
  <p>not to make the actual request but to always return:</p>
  
  <pre><code>{'products' =&gt; [{id: 1, name: 'Product 1'}, {id: 2, name: 'Product 2'}]
  </code></pre>
  
  <p>Doing it with the AngularJS <code>$httpBackend</code> service would be easy:</p>
  
  <pre><code>$httpBackend
      .when('GET', '/products')
      .respond("{id: 1, name: 'Product 1'}, {id: 2, name: 'Product 2'}")
  </code></pre>
  
  <p>Any idea on how to achieve this with Guzzle 6?</p>