php-vcr icon indicating copy to clipboard operation
php-vcr copied to clipboard

Do identical requests get replayed in sequence?

Open bensheldon opened this issue 9 years ago • 12 comments

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.

bensheldon avatar Jul 27 '15 19:07 bensheldon

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 avatar Jul 28 '15 17:07 adri

@adri well nuts :-)

For the usecase, we're writing behat stories. Many of our stories involve some sort of flow like:

  1. read out and verify the original value (GET)
  2. modify the value (PUT)
  3. 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).

bensheldon avatar Jul 28 '15 17:07 bensheldon

@adri Also, we (@pantheon-systems), would be willing to sponsor/bounty this feature. Please email me at [email protected] if you'd be interested.

bensheldon avatar Jul 29 '15 18:07 bensheldon

As @bensheldon as a quick workaround when we do this we just pop in a separate cassette for step 3.

EdwardIII avatar Oct 01 '15 16:10 EdwardIII

#160 should enable this scenario

chrisrichard avatar Jun 11 '16 05:06 chrisrichard

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 avatar Jul 08 '16 08:07 esbenp

@esbenp yes, thank you. That looks like exactly what I'm looking for. Thank you for resurrecting this issue. 🐣

bensheldon avatar Jul 11 '16 21:07 bensheldon

Perfect @bensheldon. What do you say @adri, should I fix tests and make a real PR?

Ping @castarco are you co-maintaining?

esbenp avatar Jul 12 '16 05:07 esbenp

Yes that would be awesome!

adri avatar Jul 12 '16 06:07 adri

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.

esbenp avatar Jul 13 '16 17:07 esbenp

ping @castarco @adri

esbenp avatar Aug 04 '16 17:08 esbenp

ping @castarco @adri

esbenp avatar Sep 09 '16 06:09 esbenp