-
Notifications
You must be signed in to change notification settings - Fork 207
Dispatch before playback event for each http interaction in cassette #118
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
Conversation
foreach ($this->storage as $recording) { | ||
$storedRequest = Request::fromArray($recording['request']); | ||
if ($dispatchEvents) { | ||
$this->config->dispatch(VCREvents::VCR_BEFORE_PLAYBACK, new BeforePlaybackEvent($request, $this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the request of the BeforePlaybackEvent should be the storedRequest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks!
Thanks. I think its all good except that dispatching events happens in the configuration. Is this only for convenience? Why not create a event dispatcher class which is injected into the classes which need it? |
Well it's ok for now. Can you please rebase? |
@adri, I dispatched from configuration for convenience, like you said. I believe this is how I saw it in Ruby. When you ask me to rebase, do you mean squash my two commits into one? Or do you mean rebase the branch onto master? |
Hey Tyler, Ah yeah I meant rebasing the branch on master. At the moment I can't merge automatically :-) |
You already merged aaa2000's pull request, right? My pull request is incompatible. We wouldn't want both implementations. I gave you push access to my fork in case I'm misunderstanding and you want to take care of it quickly yourself. |
Ok I understand. Should the |
In Ruby it is https://www.relishapp.com/vcr/vcr/v/2-9-1/docs/hooks/before-playback-hook
I read it as it is issuing only one event, am I wrong? |
It's up to us I suppose, but that's how it's done in Ruby's VCR. I was just trusting that they did that for a good reason, and not an arbitrary one. But I admit I didn't do research to verify, and nothing jumps out at me as to do it one way or the other.
I think this sentence: |
I prefer @tylercollier implementation because my PR dispatches the VCR_BEFORE_PLAYBACK and VCR_AFTER_PLAYBACK event when the cassette has no response. I think that it breaks the VCRBundle https://github.com/php-vcr/VCRBundle/blob/master/EventListener/PlaybackListener.php#L26 |
@adri Did you have a chance to look at this? We just implemented a deployment strategy which requires all tests to pass before it will deploy, so my co-workers and I are depending on this change. We will use it to ignore HTTP headers with PHP/Curl version differences. |
Not yet unfortunately. I hope I will soon.
This should be possible with using custom request matchers. You can disable the |
Here's what I did in the meantime:
|
Closing in favour of #127. |
Fix for #101.
As I mention in this comment, I followed Ruby VCR's lead (and aaa2000's suggestion) and dispatch the "before playback" event before each HTTP interaction in the cassette.
I did not do change the 'after playback' event, since there should be one anyway.
I did end up moving the dispatch into the configuration, a la Ruby's VCR. This means the
dispatch
method needs to be public.