Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Does PHP-VCR work with stream_context_create? #96
I'm using the expert-sender-api library. The request in the cassette that ends up recorded is almost blank:
There should be a request body, and the content-length should not be zero (it's also odd it's a string, no?). Also, the method there is GET, but it should be POST. If I disable PHP-VCR, and perform a live web service call, the request goes out as I expect and then I get a proper response. So something is not right or fully handled by PHP-VCR here.
If I enabled PHP-VCR and let it send the blank request, it captures the response. As you might expect, it's a response to the blank request, but in my case, the response contains 9 headers and an XML body that I'd expect. So that part works.
The expert-sender-api library's
If I manually create the cassette request, there's still another problem. Weirdly (this is directly from the php manual):
The fatal error I get with PHP-VCR is:
That variable is from line 32. Is it possible for PHP-VCR to handle this? I know essentially how PHP-VCR works, and I can't imagine it dealing with that. Searching the source code for
Regarding the "there's still another problem". I just ran a different test with PHP-VCR off and not cassette loaded. I received a response using
Thank you very much. Indeed the stream wrapper interception is only tested with GET requests. Header support was added quite recently. The response headers seem to be indeed not recorded. Definitely some work and tests to be done here :-/ thank you for pointing this out.
This should be fixed. I would be very happy to merge a pull request as I'm again limited on time.
I've been looking into this. I think the problem I found originally was because the server I was connecting to is sending an intermediate
Unfortunately, I don't know how to test this in the tests. Doing the above actually throws away the
@adri, I'd love your in-depth PHP knowledge on how to handle the $http_response_header situation. As I noted from the linked documentation, it's a local variable that's magically brought into existence by PHP when using the stream wrappers. How can PHP-VCR invoke this behavior? My googling got me nowhere!
This is a hard one. I'm just brainstorming a bit...
It is possible to overwrite
There are projects like PHP-Parser which can be used to parse PHP source code. We could implement a check if some stream wrapper function is called and
I think it could be solved but it requires work and lots of testing.