Skip to content
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

Replying with a custom Response #1

Open
someniatko opened this issue Apr 21, 2023 · 2 comments
Open

Replying with a custom Response #1

someniatko opened this issue Apr 21, 2023 · 2 comments

Comments

@someniatko
Copy link

someniatko commented Apr 21, 2023

First of all, this library is exactly what I was looking for, and I have found nothing comparable to it (php-http/mock-client lib is dated and also very barebones in comparison to this one), thank you!

For now the intended way of crafting a response is to use the library's PockResponseBuilder. However, I'd like to just put my own response implementing PSR's ResponseInterface, like that:

$myResponse = new Response(); // assume Response is a class from some PSR-7 implementation.
$builder = new PockBuilder();
$builder->replyWith($myResponse); // replyWith() is just some suggested method name
@Neur0toxine
Copy link
Owner

Hello. You can use PockBuilder::replyWithCallback method. The callback will receive two arguments: RequestInterface and PockResponseBuilder. You can safely ignore those and just return any ResponseInterface implementation.

@someniatko
Copy link
Author

Thank you! This is a bit verbose and I would prefer to just pass a response directly (maybe internally PockBuilder could call this replaceWithCallback() method though), but this works as well.

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

No branches or pull requests

2 participants