-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Add a Record & Replay callback to the MockHttpClient. #35677
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
@GaryPEGEOT Do you have time to finish this PR? |
8b70fec
to
bb9fb03
Compare
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.
What about making this way simpler, by just recording + replaying the req/resp in order?
Right now, the hashing logic makes me think of this as a special cache layer, not a record-replay tape.
I feel like we might prefer implementing a real HTTP cache and make it able to force-store+serve requests, and have this one specialized on in-order serving.
WDYT?
*/ | ||
private $client; | ||
|
||
public function __construct(string $mode, CacheItemPoolInterface $cache, HttpClientInterface $client = null) |
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.
Shouldn't we make the mode optional, defaulting to MODE_REPLAY_OR_RECORD?
That would ease integration with tests I believe: one wants to re-record? => bin/console cache:pool:clear some_pool_for_some_reqs
then run the tests again.
WDYT?
$response = null; | ||
|
||
if (isset($options['body'])) { | ||
$parts[] = md5(static::getBodyAsString($options['body'])); |
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.
better not use md5 for this.
we could use hash_init()
instead of the $parts
array
For inspiration btw: https://github.com/ikwattro/guzzle-stereo/ |
#35893 has been merged now. |
92aff83
to
2c57469
Compare
2c57469
to
f37ffc0
Compare
3c8a78f
to
9c46eb3
Compare
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.
Thanks this moves forward nicely.
One thing that doesn't work right now is async: the way this is currently implemented break async and streaming when recording.
It should be possible to record without breaking async by leveraging AsyncDecorator.
Up to continue this way?
|
||
protected function setUp(): void | ||
{ | ||
$recorder = new ResponseRecorder(sys_get_temp_dir(), new ResponseSerializer()); |
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.
we should clean up the temporary files created when running the tests
$this->client = new MockHttpClient($this->callback); | ||
} | ||
|
||
public function testReplayOrRecord(): void |
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.
please remove all : void
from all test cases
private $client; | ||
|
||
/** | ||
* @var ResponseRecorder |
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.
let's remove all @var
that duplicate the constructor, they're useless
Closing as we discussed on Slack: we should try another approach based on AsyncDecoratorTrait, that would share some logic/classes between this use case and the "client-side http-cache" use case. |
@nicolas-grekas Has there been any progress or new leads on this feature ? |
Allow to record & replay responses for test / dev purpose:
TODO: