Behat / WebApiExtension

Behat extension to test web APIs
http://extensions.behat.org
MIT License
111 stars 114 forks source link

Expose the response object #54

Closed christeredvartsen closed 1 year ago

christeredvartsen commented 8 years ago

This PR adds a getResponse() method to the Behat\WebApiExtension\Context\WebApiContext class so that classes extending this can access the response instance. Will solve #45.

I have a context class that adds some @Given/@When/@Then that uses the response instance that uses the code added in this PR as well.

stof commented 8 years ago

a getter with a mixed returned type makes it quite hard to use IMO

christeredvartsen commented 8 years ago

I'm not sure why \GuzzleHttp\Message\ResponseInterface is mentioned anyways. That interface does not exist in the version of Guzzle that is installed when doing a simple composer install after cloning this project. The guzzle response (GuzzleHttp\Psr7\Response) that is being used implements Psr\Http\Message\ResponseInterface, so it might very well be that the first part of the existing @var hint is obsolete?

stof commented 8 years ago

@christeredvartsen We support both guzzle 5 and guzzle 6. the version being installed depends on your PHP version and on other constraints in the project (some other package may be incompatible with Guzzle 6). this is why the response property can have 2 different types

christeredvartsen commented 8 years ago

OK. The other way to make the response instance available for sub classes is to make it protected, but that does not seem like a better / worse solution to me.

SebastienTainon commented 8 years ago

I think the response should be exposed too @stof

Here's an example: I want to check that the response matches some pattern without reimplementing all the iSendARequestWith... functions.

How can I do this? My opinion is that I can extend your WebApiContext and add a new function like theResponseShouldMatchCustomPattern but in this function I need the response from the WebApiContext, however I can't access it because it is private.

Do you have a solution for this? I think exposing the response either way would make everything easier.

lossendae commented 8 years ago

Hello,

I just encountered the same issue where I wanted to check a specific key for JSON response array in my FeatureContext but can't access the response property.

Is there a good reason why those methods and properties visibility where set to private ?

mkosiedowski commented 7 years ago

Any news on this pull request? I would also like to have response object visible in sub classes so I can write more detailed tests

douglaslinsmeyer commented 7 years ago

+1, Same as @lossendae

fabamatic commented 7 years ago

+1 You are shooting yourself in the foot by not making the response accesible. My tests are complex and require data from the response.

theweekendgeek commented 7 years ago

+1, I came across this today as I wanted to extend the WebApiContext with some custom functions