php-http / message-factory

Abandoned: Httplug Factory interfaces for PSR-7 HTTP Message
http://php-http.org
MIT License
1.38k stars 10 forks source link

Add request as an argument #35

Closed GaryPEGEOT closed 6 years ago

GaryPEGEOT commented 6 years ago

Add an optional request argument to allow programmatically generated response in tests for example (Like fetching a file based on request URI / path).

dbu commented 6 years ago

changing the interface signature would be a BC break and require us to bump the major version.

can you explain a bit more why you need this? the idea of the response factory is to not need to bind to a specific psr 7 implementation. i think regular code would never pass the request into the factory, so i don't see how this would be useful. if your application does something with a request to create a response, it should implement that logic itself, and then use the factory to create the response object from the response data, i think.

GaryPEGEOT commented 6 years ago

I would like to use the mock-client to fetch a file based on request URI and populate response body with the file content in my functional tests, to simulate webservices response. I can add response to the mock client, but doing it on each paths / request is a bit cumbersome.

dbu commented 6 years ago

you can add several responses to the mock client and it will return them in order (also exceptions if you need). this is not perfect as it assumes a sequence of requests which might be too much detail knowledge about your app but could work for some scenarios.

i think anything that goes beyond that should be done with your customer mock client implementation (for example https://github.com/php-http/mock-client/pull/24)

thus i am -1 on merging this pull request. but thanks for contributing, don't let this discourage you from further contributing ;-)