Giter Club home page Giter Club logo

guzzlehttpmock's People

Contributors

eschwartz avatar juliapoberezhnaia avatar maartenderie avatar narcoticfresh avatar plorenz-etes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

guzzlehttpmock's Issues

Support to expect multiple requests in one tests

The original functionality makes one feel it should be possible to set up multiple expectations in one test scenario, e.g.:

  • Expect a GET request /test
  • Expect a POST request /test
  • Expect a GET request /somewhere

In fact, this tests does not run through. The counter contained output shows the encountered three requests and maps them to one expected request only: the first of the tree which were set up.

I suspect the expected_count is only for replaying the same request multiple times, not for separate requests in one tests. But sometimes it is necessary for the integrity. We should extend the framework to expect multiple requests in the order in which they were set up, distinguishing between an individual expected_count and a total one.

Can't make it work, mock always returns 200 status code

A slightly modified code from the readme (after fixing the namespace with \Aeris\GuzzleHttpMock\ instead of \Aeris\GuzzleHttp\):

$httpMock = new \Aeris\GuzzleHttpMock\Mock();

// Create a guzzle http client and attach the mock handler
$guzzleClient = new \GuzzleHttp\Client([
	'base_url' => 'http://www.example.com',
	'handler' => $httpMock->getHandlerStackWithMiddleware()
]);

// Setup a request expectation
$httpMock
	->shouldReceiveRequest()
    ->withUrl('http://www.example.com/foo')
    ->withMethod('GET')
    ->withBodyParams([ 'foo' => 'bar' ])
    ->andRespondWithJson([ 'faz', 'baz' ], 403);

// Make a matching request
$response = $guzzleClient->get('/foo', ['json' => ['foo' => 'bar'] ]);
echo $response->getStatusCode(); //200, even though it should return 403

What am I doing wrong?

Testing the request headers

It would be great if the library had also the ability to validate the request headers. Some APIs require certain headers being set and currently there's no way to test it using this library. You have revert to the built-in mocking capabilities of Guzzle, which are much lower-level and not so easy to use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.