Search code examples
phpunit-testingmockingputguzzle

How to inspect the payload of a guzzle request


Guzzle includes a simple NodeJS server for testing, and I am using that to mock my backend. The server contains a getReceivedRequests method which returns a list of all the requests that it had received, and I am trying to inspect the requests to make sure my program is sending them correctly.

For GET requests it's easy enough. Looking at the Request class, I can get the query parameters and assert on them.

The question comes when I am trying to inspect a PUT request. Looking at the Request class there seems to be no way for me to get its payload. In fact I don't even know where the payload is stored in the object, as there is no private fields indicated as such.

Is there anyway I can assert on the payload of a guzzle request?


Solution

  • I use that to inspect and debug my request payload

    $request->getBody()->read($request->getBody()->getSize())