UriTemplateHttpClient example

namespace Symfony\Component\HttpClient\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\UriTemplateHttpClient;

final class UriTemplateHttpClientTest extends TestCase
{
    public function testExpanderIsCalled()
    {
        $client = new UriTemplateHttpClient(
            new MockHttpClient(),
            function Dstring $url, array $vars): string {
                $this->assertSame('https://foo.tld/{version}/{resource}{?page}', $url);
                $this->assertSame([
                    'version' => 'v2',
                    'resource' => 'users',
                    'page' => 33,
                ]$vars);

                return 'https://foo.tld/v2/users?page=33';
            },
            [
Home | Imprint | This part of the site doesn't use cookies.