setResponseFactory example

use HttpClientTrait;

    private ResponseInterface|\Closure|iterable|null $responseFactory;
    private int $requestsCount = 0;
    private array $defaultOptions = [];

    /** * @param callable|callable[]|ResponseInterface|ResponseInterface[]|iterable|null $responseFactory */
    public function __construct(callable|iterable|ResponseInterface $responseFactory = null, ?string $baseUri = 'https://example.com')
    {
        $this->setResponseFactory($responseFactory);
        $this->defaultOptions['base_uri'] = $baseUri;
    }

    /** * @param callable|callable[]|ResponseInterface|ResponseInterface[]|iterable|null $responseFactory */
    public function setResponseFactory($responseFactory): void
    {
        if ($responseFactory instanceof ResponseInterface) {
            $responseFactory = [$responseFactory];
        }

        
public function testHttp2PushVulcainWithUnusedResponse()
    {
        $this->markTestSkipped('MockHttpClient doesn\'t support HTTP/2 PUSH.');
    }

    public function testChangeResponseFactory()
    {
        /* @var MockHttpClient $client */
        $client = $this->getHttpClient(__METHOD__);
        $expectedBody = '{"foo": "bar"}';
        $client->setResponseFactory(new MockResponse($expectedBody));

        $response = $client->request('GET', 'http://localhost:8057');

        $this->assertSame($expectedBody$response->getContent());
    }

    public function testStringableBodyParam()
    {
        $client = new MockHttpClient();

        $param = new class() {
            
Home | Imprint | This part of the site doesn't use cookies.