Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Tests\Unit;
use GuzzleHttp\Psr7\Response;use PHPUnit\Framework\TestCase;use Wotnak\Atproto\Http\BoundedResponseBody;
/** * Tests bounded response-body reads. */final class BoundedResponseBodyTest extends TestCase {
public function testReadsBodyAtLimit(): void { static::assertSame( '12345', BoundedResponseBody::read(new Response(200, [], '12345'), 5), ); }
public function testRejectsBodyPastLimit(): void { $this->expectException(\LengthException::class); BoundedResponseBody::read(new Response(200, [], '123456'), 5); }
public function testRejectsOversizedDeclaredContentLengthBeforeReading(): void { $this->expectException(\LengthException::class); BoundedResponseBody::read( new Response(200, ['Content-Length' => '100'], 'small'), 10, ); }
public function testReadsWhilePreservingStreamPosition(): void { $response = new Response(200, [], 'abcdef'); $response->getBody()->seek(3);
static::assertSame('abcdef', BoundedResponseBody::readPreservingPosition($response, 6)); static::assertSame(3, $response->getBody()->tell()); }
public function testPreservingReadReturnsNullForOversizedBodyAndRestoresPosition(): void { $response = new Response(200, [], 'abcdef'); $response->getBody()->seek(2);
static::assertNull(BoundedResponseBody::readPreservingPosition($response, 5)); static::assertSame(2, $response->getBody()->tell()); }
}