Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Tests\Unit;
use GuzzleHttp\Psr7\HttpFactory;use GuzzleHttp\Psr7\Response;use PHPUnit\Framework\TestCase;use Wotnak\Atproto\AtprotoClientFactory;use Wotnak\Atproto\Security\OutboundUrlPolicy;use Wotnak\Atproto\Tests\Support\FactoryTestHttpClient;use Wotnak\Atproto\Tests\Support\TestAuthenticatedSession;
/** * Tests client composition through the reusable factory. */final class AtprotoClientFactoryTest extends TestCase {
public function testCreateBuildsFacadeWithDefaultServiceUrl(): void { $factory = new HttpFactory(); $clientFactory = new AtprotoClientFactory( new FactoryTestHttpClient(new Response(200, [], '{}')), $factory, $factory, urlPolicy: new OutboundUrlPolicy(), );
$client = $clientFactory->create('https://pds.example');
static::assertSame('https://pds.example', $client->getDefaultServiceUrl()); static::assertSame([], $client->get('com.atproto.repo.describeRepo', ['repo' => 'alice.example'])); }
public function testCreateAcceptsAnExplicitLocalDevelopmentUrlPolicy(): void { $factory = new HttpFactory(); $clientFactory = new AtprotoClientFactory( new FactoryTestHttpClient(new Response(200, [], '{}')), $factory, $factory, );
$client = $clientFactory->create( 'http://localhost:2583', urlPolicy: new OutboundUrlPolicy(allowedDevelopmentHosts: ['localhost']), );
static::assertSame([], $client->get('com.atproto.repo.describeRepo', ['repo' => 'alice.test'])); }
public function testCreateAuthenticatedBindsCredentialsToExplicitServiceUrl(): void { $factory = new HttpFactory(); $clientFactory = new AtprotoClientFactory( new FactoryTestHttpClient(new Response(200, [], '{}')), $factory, $factory, urlPolicy: new OutboundUrlPolicy(), );
$client = $clientFactory->createAuthenticated( new TestAuthenticatedSession('did:plc:abc', 'https://pds.example', 'token-value'), 'https://service.example', );
static::assertSame([], $client->get('com.atproto.server.getSession')); }
}