New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement recording of identical requests with backwards compatibility and separation of concerns. #270
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…le Cassette to playback and record request/responses at a given index. Do not require Cassette to manage index state.
… the recording index.
…y exists in the cassette.
… no index keys playback.
…ed cassettes playback multiple identical requests correctly.
…is called as part of eject() and insertCassette().
@JeroenVanOort might you consider this for 1.5? |
I used this feature successfully for more than 3 years now! Is it possible to merge it so it is available for all upcoming releases? It sucks using a forked version including that feature. :-) |
I'll close this PR, because i rebased your version onto master. See #270 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
This PR was inspired by #161 and it fixes #132. #161 didn't quite work for our use case.
Cassette::hasResponse()
caused Cassette::$indexTable to be incremented resulting in non-sequential indexes and off-by-one issues.Use case
Terminus uses phpVCR. Certain Behat tests run commands that repeatedly check the status of a task. When the task finishes its status changes from null to 'success' or 'failed'. With phpVCR 1.4.4 only the first status check request is recorded.
What has been done
I've repurposed some of the methods from #161, but I've removed
Cassette::$indexTable
and added an$indexTable
property to Videorecorder instead. The thinking here is that$indexTable
manages state and moving this responsibility to Videorecorder maintains better separation of concerns. (In fact making this change required no adjustments to existing unit tests.)Cassette::playback()
:$index
parameter (making it possible to playback a specific index multiple times -- should such a need arise).Videorecorder::handleRequest()
:Cassette:playback()
using the optional parameter.New unit tests:
testPlaybackOfIdenticalRequestsFromLegacyCassette()
ensures proper behavior with legacy cassettes.testPlaybackOfIdenticalRequests()
ensures proper behavior with indexed cassettes.testInsertCassetteEjectExisting()
ensure thatVideorecorder::resetIndex()
is called.How to test
composer install
andcomposer test
and ensure that tests are passing.index: N
key value at the end of the request/response recording. Play back the recording and observe that the responses are played back sequentially.Thanks
Thanks to @dsnopek for his input!