php-vcr
php-vcr copied to clipboard
Do identical requests get replayed in sequence?
Will PHP-VCR record multiple requests to the same matching resource and then play them back in order? This is implemented in the Ruby VCR Library but it seems like it isn't implemented in PHP-VCR (unless I'm just using the library wrong).
Sorry to ask a question, but I couldn't find the answer in the docs or quickly in the code. Thanks for the help.
Hey Ben. Thanks a lot for your question. This feature is indeed currently not implemented.
I'm interested... how did you come across this usecase?
@adri well nuts :-)
For the usecase, we're writing behat stories. Many of our stories involve some sort of flow like:
- read out and verify the original value (GET)
- modify the value (PUT)
- refetch the value in step 1(GET) and verify that it's been modified
So we're making the same GET request twice, but expecting a different response in order to verify that the PUT is operating correctly (as well as we're properly flushing caches within our own application).
@adri Also, we (@pantheon-systems), would be willing to sponsor/bounty this feature. Please email me at [email protected] if you'd be interested.
As @bensheldon as a quick workaround when we do this we just pop in a separate cassette for step 3.
#160 should enable this scenario
Ping @bensheldon @adri what do you guys think of this fix https://github.com/esbenp/php-vcr/commit/278a11b75621cff16d04e212eb9258a735efc844 ?
If we have a test that has the following requests:
- (1)
GET /resource
- (2)
PUT /resource
- (3)
GET /resource
This commit keeps track of the order of occurrence of requests, meaning (1) is the 1st occurrence of (GET /resource) and (3) is the 2nd. When the test is re-run, when running (3) PHP-VCR will now look for a saved request which is the 2nd (GET /resource).
I have not tested thoroughly and I am a little unsure on the side effects of this as I am not that familiar with the library and its usage in general. However it seemed to fix the issue for our test suite. Maybe any of you can se any problems with this approach?
Right now the tests are failing but if you like the fix I can start looking into the tests and make an actual PR. Let me know what you think.
@esbenp yes, thank you. That looks like exactly what I'm looking for. Thank you for resurrecting this issue. 🐣
Perfect @bensheldon. What do you say @adri, should I fix tests and make a real PR?
Ping @castarco are you co-maintaining?
Yes that would be awesome!
Ping @adri @castarco @bensheldon
PR is here #161
I got the tests to work on my local machine by simulating "the end of a test case" by resetting the indexTable between recording responses and playing them back. Let me know what you think.
ping @castarco @adri
ping @castarco @adri