mirror of
https://github.com/Neur0toxine/pock.git
synced 2024-11-28 15:56:09 +03:00
real networking for mocked requests
This commit is contained in:
parent
f7832865a1
commit
dcc642a0ea
@ -126,6 +126,6 @@ In order to use unsupported serializer you should create an adapter which implem
|
|||||||
- [x] Form Data body matcher (partial & exact)
|
- [x] Form Data body matcher (partial & exact)
|
||||||
- [x] Multipart form body matcher (just like callback matcher but parses the body as a multipart form data)
|
- [x] Multipart form body matcher (just like callback matcher but parses the body as a multipart form data)
|
||||||
- [x] **BREAKING CHANGE:** Rename serializer decorators to serializer adapters.
|
- [x] **BREAKING CHANGE:** Rename serializer decorators to serializer adapters.
|
||||||
|
- [x] Real network response for mocked & unmatched requests.
|
||||||
- [ ] `symfony/http-client` support.
|
- [ ] `symfony/http-client` support.
|
||||||
- [ ] Real network response for mocked & unmatched requests.
|
|
||||||
- [ ] Document everything (with examples if it’s feasible).
|
- [ ] Document everything (with examples if it’s feasible).
|
||||||
|
@ -46,6 +46,8 @@ use Pock\Traits\JsonDecoderTrait;
|
|||||||
use Pock\Traits\JsonSerializerAwareTrait;
|
use Pock\Traits\JsonSerializerAwareTrait;
|
||||||
use Pock\Traits\XmlSerializerAwareTrait;
|
use Pock\Traits\XmlSerializerAwareTrait;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -645,6 +647,22 @@ class PockBuilder
|
|||||||
$this->replyWithFactory(new CallbackReplyFactory($callback));
|
$this->replyWithFactory(new CallbackReplyFactory($callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reply to the request using provided client. Can be used to send real network request.
|
||||||
|
*
|
||||||
|
* @param \Psr\Http\Client\ClientInterface $client
|
||||||
|
* @SuppressWarnings(unused)
|
||||||
|
*/
|
||||||
|
public function replyWithClient(ClientInterface $client): void
|
||||||
|
{
|
||||||
|
$this->replyWithCallback(function (
|
||||||
|
RequestInterface $request,
|
||||||
|
PockResponseBuilder $responseBuilder
|
||||||
|
) use ($client): ResponseInterface {
|
||||||
|
return $client->sendRequest($request);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the builder.
|
* Resets the builder.
|
||||||
*
|
*
|
||||||
|
@ -1041,6 +1041,25 @@ EOF;
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReplyWithClient(): void
|
||||||
|
{
|
||||||
|
$inlined = new PockBuilder();
|
||||||
|
$inlined->reply(429);
|
||||||
|
|
||||||
|
$builder = new PockBuilder();
|
||||||
|
$builder->matchMethod(RequestMethod::GET)
|
||||||
|
->matchUri(self::TEST_URI)
|
||||||
|
->always()
|
||||||
|
->replyWithClient($inlined->getClient());
|
||||||
|
|
||||||
|
$response = $builder->getClient()->sendRequest(self::getPsr17Factory()->createRequest(
|
||||||
|
RequestMethod::GET,
|
||||||
|
self::TEST_URI
|
||||||
|
));
|
||||||
|
|
||||||
|
self::assertEquals(429, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
public function matchXmlNoXslProvider(): array
|
public function matchXmlNoXslProvider(): array
|
||||||
{
|
{
|
||||||
$simpleObject = <<<'EOF'
|
$simpleObject = <<<'EOF'
|
||||||
|
Loading…
Reference in New Issue
Block a user