Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Tests\Unit;
use GuzzleHttp\Psr7\HttpFactory;use GuzzleHttp\Psr7\NoSeekStream;use GuzzleHttp\Psr7\Response;use GuzzleHttp\Psr7\Utils;use PHPUnit\Framework\TestCase;use Wotnak\Atproto\AtprotoClient;use Wotnak\Atproto\Client\XrpcClient;use Wotnak\Atproto\Identity\DidResolver;use Wotnak\Atproto\Identity\HandleResolver;use Wotnak\Atproto\Security\OutboundUrlPolicy;use Wotnak\Atproto\Tests\Support\FacadeTestHttpClient;use Wotnak\Atproto\Tests\Support\TestXrpcRequestSender;
/** * Tests the AT Protocol facade. */final class AtprotoClientTest extends TestCase {
public function testFacadeReturnsTransportAndIdentityServices(): void { $factory = new HttpFactory(); $urlPolicy = new OutboundUrlPolicy(); $sender = new TestXrpcRequestSender([new Response(200), new Response(200, [], '{}')]); $xrpc = new XrpcClient( $sender, $factory, $factory, 'https://pds.example', $urlPolicy, ); $handles = new HandleResolver( new FacadeTestHttpClient(new Response(200, [], 'did:plc:abc')), $factory, urlPolicy: $urlPolicy, ); $dids = new DidResolver(new FacadeTestHttpClient(new Response(200, [], '{}')), $factory, urlPolicy: $urlPolicy);
$client = new AtprotoClient($xrpc, $handles, $dids);
static::assertSame('https://pds.example', $client->getDefaultServiceUrl()); static::assertSame($handles, $client->handles()); static::assertSame($dids, $client->dids());
$client->requestWithoutBody('POST', 'com.atproto.server.refreshSession'); static::assertNotNull($sender->lastRequest); static::assertSame('', (string) $sender->lastRequest->getBody()); static::assertSame('', $sender->lastRequest->getHeaderLine('Content-Type'));
$stream = new NoSeekStream(Utils::streamFor('streamed-body')); $client->postRaw('com.atproto.repo.uploadBlob', $stream); static::assertSame($stream, $sender->lastRequest?->getBody()); }
}