Skip to content

[Plugin] Add VCR Record & Replay plugins #3

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

Merged
merged 8 commits into from
Mar 30, 2019
Merged

[Plugin] Add VCR Record & Replay plugins #3

merged 8 commits into from
Mar 30, 2019

Conversation

GaryPEGEOT
Copy link
Collaborator

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
Documentation TODO
License MIT

What's in this PR?

Add a VCR like plugin to allow storing and replaying response

Why?

Allow user to do functional tests why production-like data and provide same functionality as CsaGuzzleBundle

Example Usage

<?php

use Http\Client\Plugin\Vcr\NamingStrategy\PathNamingStrategy;
use Http\Client\Plugin\Vcr\Recorder\FilesystemRecorder;
use Http\Client\Plugin\Vcr\RecordPlugin;
use Http\Client\Plugin\Vcr\ReplayPlugin;

$namingStrategy = new PathNamingStrategy();
$recorder = new FilesystemRecorder('some/dir/in/vcs'); // You can use InMemoryRecorder as well

// To record responses:
$record = new RecordPlugin($namingStrategy, $recorder);

// To replay responses:
$replay = new ReplayPlugin($namingStrategy, $recorder);

Checklist

  • Documentation pull request created

To Do

  • make PR to the bundle to provide configuration

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job! i like the clean separation of concerns and how things are structured. the vcr header is also a good idea to help debugging.

i have some small questions, and some suggestions for documentation or simplifying things a bit more.

i updated the boilerplate from https://github.com/php-http/boilerplate/ to have consistent settings. can you please rebase on master? there might be some conflicts in boilerplate files, notably .travis.yml

@jeromegamez
Copy link
Contributor

Great job!

private function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'hash_headers' => [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was wondering if we should add defaults here (COOKIE, AUTHORIZATION, ACCEPT, ACCEPT-ENCODING, ACCEPT-LANGUAGE) but i guess most of the time you don't care, and when you do you should explicitly configure the headers you need.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think configuration it's up to the user too

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot!

@dbu dbu merged commit 7094e66 into php-http:master Mar 30, 2019
@dbu
Copy link
Contributor

dbu commented Mar 30, 2019

can you please do a pull request against https://github.com/php-http/documentation/ and maybe one for optional integration in the HttplugBundle? i'll wait a bit with tagging 1.0 so that we can still adjust if something pops up during documenting or when using it in the bundle.

@GaryPEGEOT
Copy link
Collaborator Author

Sure! I'll work on both :)

@monobook
Copy link
Contributor

monobook commented Jun 3, 2019

Hi everyone.

Is it correct that require of main lib is "php": "^5.4 || ^7.0" (and some plugins too) but here is "php": "^7.1"? And the same thing with "symfony/filesystem" and "symfony/options-resolver", I guess the versions is too high and not suitable for using with 2.* versions.

Any ideas?

Thx :)

@dbu
Copy link
Contributor

dbu commented Jun 3, 2019

yeah, this plugin requires a more recent version of php. we are currently working on cleaning up requirements of the bundle to recent php too: php-http/HttplugBundle#336

this plugin won't work with symfony 2.

@monobook
Copy link
Contributor

I see and I understand that all new stuff is cool but some people do not have 100% ability (upgrade) to use 7.1 right now in seconds... Maybe you leave some branch or tags version with old versions?

Chirs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants